首页  

Java switch tableswitch lookupswitch     所属分类 java 浏览量 607
switch支持的类型

早期只支持 byte char short int 整数类型
JDK1.5开始支持enum
1.7开始支持String,但不允许为null,借助 hashcode 实现

switch是控制选择的一种方式
编译器生成代码时可以对这种结构进行特定的优化 
产生效率比较高的代码

编译器 根据分支的情况  生成 tableswitch和lookupswitch指令
tableswitch  用于分支比较集中的情况
lookupswitch 用于分支比较稀疏的情况


Compilation of switch statements uses the tableswitch and lookupswitch instructions. 
The tableswitch instruction is used when the cases of the switch can be efficiently represented as indices into a table of target offsets. 
The default target of the switch is used if the value of the expression of the switch falls outside the range of valid indices.
Where the cases of the switch are sparse, 
the table representation of the tableswitch instruction becomes inefficient in terms of space. 
The lookupswitch instruction may be used instead.

上一篇     下一篇
归并排序与快速排序

一些有趣的技术网站

程序数据结构与算法

算法精粹 经典计算机科学问题的Python实现 关键术语

二叉树的几个重要性质

关于数学的名言