开发者

Is this Scala code correct?

Why does this code crash the Scala 2.8.1 compiler?

val a = new Array[{ var x = 1 }](3)

Is it a compiler bug?

Anyway is it a legal Scala code? (I want an array of objects with anonymous class type)

Update开发者_JAVA技巧:

What I want is something like:

class X { var x = 1}
val a = new Array[X](3)

but without having to define standalone X


Compiler crashes are always bugs. But why are you trying to set x equal to 1 in the type declaration?

Your probably want one of these:

val a = new Array[{var x: Int}](3)
val a = Array.fill(3)(new { var x = 1 })

(and the compiler is happy with either of these).


It doesn't crash for me (Scala 2.8), so it is likely a bug.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜