Byte/Char
Short/Int/Long/Float/Double
Boolean

一、赋值

scala> val a:Int = 10
a: Int = 10

scala> val b:Boolean = true
b: Boolean = true

scala> val d = 1.1
d: Double = 1.1

scala> val e:Float = 1.2    // 默认会解析成Double,所以报错
<console>:11: error: type mismatch;
 found   : Double(1.2)
 required: Float
       val e:Float = 1.2
                     ^

scala> val e:Float = 1.2f    // 在数字后面加上 f,转换成Float类型
e: Float = 1.2

二、类型转换

scala> val f = 10
f: Int = 10

scala> val g = 10.asInstanceOf[Double]    // 类型转换
g: Double = 10.0

三、类型判断

scala> val h = 10.is
isInfinite   isInfinity   isInstanceOf   isNaN   isNegInfinity   isPosInfinity   isValidByte   isValidChar   isValidInt   isValidLong   isValidShort   isWhole

输入过程,按 tab 建,可以查看所有不全代码

scala> val h = 10.isInstanceOf[Int]
h: Boolean = true

scala> val h = 10.isInstanceOf[Double]
h: Boolean = false