变量

1.常量--不可更该

scala> val helloString="Hello World"
helloString: String = Hello World
scala> helloString="Hello Crazy World"
<console>:8: error: reassignment to val
       helloString="Hello Crazy World"

2.变量--可更改

scala> var helloString="Hello Cruel World"
helloString: String = Hello Cruel World

//又一次赋值
scala>  helloString="GoodBye Cruel World"
helloString: String = GoodBye Cruel World

3.延迟载入变量 lazy-变量不会立即赋值,被调用时才会赋值

scala> lazy val helloString="Hello Crazy World"
helloString: String = <lazy>

//在真正使用时被赋值
scala> helloString
res1: String = Hello Crazy World

 

posted on 2019-09-14 11:01  happygril3  阅读(128)  评论(0)    收藏  举报

导航