I used IntelliJ\'s ability to convert Java code to Scala code which generally works quite well.
It seems that IntelliJ replaced all casts with calls to asInstanceO
Well, toInt
and toLong
are not casts. The correct conversion of type casting is asInstanceOf
indeed. For example:
scala> val x: Any = 5
x: Any = 5
scala> if (x.isInstanceOf[Int]) x.asInstanceOf[Int] + 1
res6: AnyVal = 6
scala> if (x.isInstanceOf[Int]) x.toInt + 1
:8: error: value toInt is not a member of Any
if (x.isInstanceOf[Int]) x.toInt + 1
^