在以下代码中,s
scala> val s:String = null
s: String = null
//cannot check if instance is of type Null
scala> s.isInstanceOf[Null]
<console>:13: error: type Null cannot be used in a type pattern or isInstanceOf test
s.isInstanceOf[Null]
^
//s is no longer a String or Any or AnyRef
scala> s.isInstanceOf[String]
res2: Boolean = false
scala> s.isInstanceOf[AnyRef]
res4: Boolean = false
scala> s.isInstanceOf[Any]
res5: Boolean = false
scala> s.isInstanceOf[Object]
res11: Boolean = false