0

This is my class I am trying to create the following constructor for:

class StatsView(name: String, manager: AssetManager, statistics: Statistics) extends Node(name) with Control {
....

This is the object for which I am trying to use the constructor of Node

object Node {
  def apply(name: String) = new Spatial(name) with Node
  def apply() = new Spatial with Node
}

trait Node extends Spatial {

My issue is that Node is a trait causing this error message from the compiler:

trait Node is a trait; does not take constructor arguments

trait Node is a trait; does not take constructor arguments

class StatsView(name: String, manager: AssetManager, statistics: Statistics) extends Node(name) with Control {

Hope you can help me.

4
  • 1
    Traits can only extend other traits, not classes. Commented Jan 5, 2014 at 3:25
  • @DaoWen My issue is that I need to call the super constructor of Node. Commented Jan 5, 2014 at 3:32
  • 1
    @DaoWen Yes, they can: stackoverflow.com/questions/12854941/… Commented Jan 5, 2014 at 4:15
  • @AlexeyRomanov - Thanks for the correction. The ways that the extends and abstract keywords are overloaded in Scala can be very confusing at times. I've always considered that relationship as a restriction on the trait rather than an inheritance relationship, but I guess you could think of it either way. Anyway, I totally misunderstood the issue at hand (I thought he was trying to make a super-constructor call from Node to Spatial, not StatsView to Node). Sorry about that. Commented Jan 5, 2014 at 5:34

1 Answer 1

4

The problem is that Node(name) is just a method call and so can't be in extends. You need to write the type like this:

class StatsView(name: String, manager: AssetManager, statistics: Statistics) extends 
  Spatial(name) with Node { ... }

My issue is that I need to call the super constructor of Node

Since Node isn't a class, it doesn't have a super constructor.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.