0
votes

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.

1
Traits can only extend other traits, not classes. - DaoWen
@DaoWen My issue is that I need to call the super constructor of Node. - miniwolf
@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. - DaoWen

1 Answers

4
votes

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.