scala学习笔记:理解lazy值
scala> var counter = 0
counter: Int = 0
scala> def foo = {counter += 1; counter}
foo: Int
scala> val value1 = foo; lazy val value2 = foo; def value3 = foo
value1: Int = 1
value2: Int = <lazy>
value3: Int
scala> value1
res39: Int = 1
scala> value1
res40: Int = 1
scala> value2
res41: Int = 2
scala> value2
res42: Int = 2
scala> value3
res43: Int = 3
scala> value3
res44: Int = 4
+++++++++++++++++++++++++++++++++++++++++++
如本文存在任何侵权部分,请及时告知,我会第一时间删除!
转载本博客原创文章,请附上原文@cnblogs的网址!
QQ: 5854165 我的开源项目 欢迎大家一起交流编程架构技术&大数据技术! +++++++++++++++++++++++++++++++++++++++++++
如本文存在任何侵权部分,请及时告知,我会第一时间删除!
转载本博客原创文章,请附上原文@cnblogs的网址!
QQ: 5854165 我的开源项目 欢迎大家一起交流编程架构技术&大数据技术! +++++++++++++++++++++++++++++++++++++++++++