java强制类型转换可以在源码里看到相关的东西来学习吗

泻药。原理的话要看JVM的实现和虚拟机规范了。在JVM层面类型转换使用checkcast字节码实现。关于checkcast简要说明请看checkcast 6. The Java Virtual Machine Instruction Set而且checkcast(在java中使用泛型的时候)可能会被优化,R的iteye圈子有过讨论,具体看Java泛型的性能损耗然后checkcast和instanceof指令很像,在我给你的链接中也有:The checkcast instruction is very similar to the instanceof instruction (§instanceof). It differs in its treatment of null, its behavior when its test fails (checkcast throws an exception,instanceof pushes a result code), and its effect on the operand stack.


    推荐阅读