Frage

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.

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top