字节码中Switch语句的表示形式和效率? [英] Representation and efficiency of Switch statements in bytecode?
本文介绍了字节码中Switch语句的表示形式和效率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尽管switch语句可以表示为一系列if语句,但是当将Java switch语句编译为字节码时,似乎使用了另一种方法.
Though a switch statement can be represented as a series of if statements, it appears that when a Java switch statement is compiled into bytecode, a different approach is used.
- 字节码使用什么表示?
- 我认为这种替代表示是出于效率原因,那么效率与仅if语句表示的效率相比如何?
- 还有其他因素导致使用此表示形式吗?
推荐答案
Read the spec . In Java, if you code a switch statement, then depending on various things the switch is converted into a tableswitch instruction in bytecode. Essentially a jump table. What the bytecode looks like may be irrelavent though, if the JIT can optimize it into something more efficient. This is of course, platform dependent.
这篇关于字节码中Switch语句的表示形式和效率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文