Any differences between asInstanceOf[X] and toX for value types?
问题 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 asInstanceOf . Is there any valid usage of asInstanceOf[Int] , asInstanceOf[Long] etc. for value types which can't be replaced by toInt , toLong , ...? 回答1: I do not know of any such cases. You can check yourself that the emitted bytecode is the same by compiling a class like class Conv { def b(i: Int) = i.toByte def B(i: Int) = i.asInstanceOf