我在想,为什么AnyVal不能用于isInstanceOf检查?这种行为背后的原因是什么?
scala> val c = 't'
c: Char = t
scala> c.isInstanceOf[AnyVal]
<console>:12: error: type AnyVal cannot be used in a type pattern or isInstanceO
f test
c.isInstanceOf[AnyVal]
Run Code Online (Sandbox Code Playgroud)
par*_*tic 11
AnyVal在运行时不再存在.仅在编译时.换句话说,将JVM原语视为第一类对象只是编译器"技巧".
但是,该isInstanceOf方法在运行时执行,因此无法工作.因此编译错误.
| 归档时间: |
|
| 查看次数: |
725 次 |
| 最近记录: |