代码段:
object WTF extends App {
test
val mymap = Map("Alice" -> 1, "Bob" -> 2, "Charlie" -> 3, "Dave" -> 4)
println("outter mymap="+mymap)
def test { println("inner mymap="+mymap) }
}
产生以下输出:
inner mymap=null
outter mymap=Map(Alice -> 1, Bob -> 2, Charlie -> 3, Dave -> 4)
为什么在outter之前打印内部?
为什么测试打印为空mymap?
在2.9.2上是否有DelayedInit被破坏并且有没有办法在删除“extends App”并编写我自己的main方法之后初始化内部mymap?
答案 0 :(得分:-1)
问题解决了:
object WTF extends App {
val mymap = Map("Alice" -> 1, "Bob" -> 2, "Charlie" -> 3, "Dave" -> 4)
println("outter mymap="+mymap)
test
def test { println("inner mymap="+mymap) }
}