“其实,jdk1.7并没有新的指令来处理switch string,而是通过调用switch中string.hashCode,将string转换为int从而进行判断。” 对于这句话有点错误: 我是这样验证的 public class Test { public static void main(String[] args) { String a = "Aa"; String b = "BB"; System.out.println(a.hashCode()); // a.hashCode() = 2112 System.out.println(b.hashCode()); // b.hashCode() = 2112 System.out.println(b.hashCode()==a.hashCode()); switch (a){ case "BB":System.out.println("111");break; default:System.out.println("222"); } // 输出是 222,说明switch参数为字符串时并不是string.hashCode转为int的 } } 验证是否有问题呢,请指教
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务