Super constructor cannot be passed a self referenc

2019-08-20 02:37发布

问题:

Well, I have something like this:

trait A

class Serving(a: => A)

object App extends Serving(App.Main) {
  object Main extends A
}

And I get the error super constructor cannot be passed a self reference unless parameter is declared by-name. I can work around by doing

object App extends Serving(Serv.Main)

object Serv {
  object Main extends A
}

but I don't want to. It adds 2 extra .classes and it strikes me as unelegant.

And using object App extends Serving(this.Main) also creates an error. The structure of A and Serving cannot really be changed, but is there any way to work around this error?

回答1:

Your code compiles just fine in Scala 2.8.1, even if the parameter is not declared by-name.



标签: oop scala object