int chooseNear(int i) { switch (i) { case 0: return 0; case 1: return 1; case 2: return 2; default: return -1; } } 最终生成的class文件内容如下: public class com.test19.Test07 SourceFile: "Test07.java" minor version: 0 major version: 51 flags: ACC_PUBLIC, A…
A switch statement can complete normally iff at least one of the following is true: (1)The switch block is empty or contains only switch labels. (2)The last statement in the switch block can complete normally. (3)There is at least one switch label af…
Java7中的switch支持String的实现细节 作者: zsxwing 更新: 2013-03-04 21:08:02 发布: 2012-04-26 13:58:19 在Java7之前,switch只能支持 byte.short.char.int或者其对应的封装类以及Enum类型.在Java7中,呼吁很久的String支持也终于被加上了. 例如,下面是一段switch中使用String的示例代码. public class Test { public void test(String…