0
class Cell(var x: Int)
var c = new Cell(1)
val f1 =() => c.x /* Create a closure that uses c */
def foo(e: Cell) =() => e.x /* foo is a closure generator with its own scope */
// f2 wont do any reference/deep copy
val f2 = foo(c) /* Create another closure that uses c */
val d = c /* Alias c as d */
c = new Cell(10) /* Let c point to a new object */
d.x = d.x + 1 /* Increase d.x (i.e., the former c.x) */
// now c.x refers to 10
println(f1()) /* Prints 10 */
println(f2()) /* Prints 2 */
这里F2()打印2,由于斯卡拉不会做深拷贝,为什么值依然坚持为1,它应该是10 ..我要去的地方错了斯卡拉封闭词法范围
2 )我已经阅读了一些文章,在scala中关闭不深复制对象,他们只是继续引用对象。这究竟意味着什么