基本数据类型
Byte/Char Short/Inr/Long/Double/Float Boolean
代码语言:javascript复制scala> val a :Int = 1
a: Int = 1
scala> val b :Boolean = true
b: Boolean = true
浮点型
代码语言:javascript复制scala> val c :Float = 1.234f
c: Float = 1.234
类型转换
代码语言:javascript复制scala> val d = 1.asInstanceOf[Double]
d: Double = 1.0
判断数据类型
代码语言:javascript复制scala> val f = 2.isInstanceOf[Int]
f: Boolean = true
scala> val g = 2.1234.isInstanceOf[Double]
g: Boolean = true
scala> val e = 2.1234f.isInstanceOf[Float]
e: Boolean = true
lazy
如果变量或者常量声明成lazy ,第一次使用才会计算与赋值
代码语言:javascript复制scala> lazy val h = 1
h: Int = <lazy>
scala> h
res0: Int = 1