开发者

Super constructor cannot be passed a self reference unless parameter is declared by-name

开发者 https://www.devze.com 2023-03-06 00:18 出处:网络
Well, I have something like this: trait A class Serving(a: => A) object App extends Serving(App.Main) {

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号