You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
scala>List(999L, 333).asInstanceOf[List[Long]](1)
res50:Long=333
scala>List(999, 333L).asInstanceOf[List[Long]](1)
res51:Long=333
scala>List(999, 333).asInstanceOf[List[Long]](1)
java.lang.ClassCastException: java.base/java.lang.Integer cannot be cast to java.base/java.lang.Long
at scala.runtime.BoxesRunTime.unboxToLong(BoxesRunTime.java:105)
... 28 elided
数値が同じでも型が違う
scala>9==9L
res75:Boolean=true
scala>List(9) ==List(9L)
res76:Boolean=true
scala>9.isInstanceOf[Int] ==9L.isInstanceOf[Int]
res77:Boolean=false
scala>List(9).isInstanceOf[List[Int]] ==List(9L).isInstanceOf[List[Int]]
<console>:12:warning: fruitless typetest: a value of typeList[Long] cannot also be a List[Int] (the underlying of List[Int]) (but still might match its erasure)
List(9).isInstanceOf[List[Int]] ==List(9L).isInstanceOf[List[Int]]
^
res79:Boolean=true