JDK7之后switch支持String
之前,switch支持的类型只有byte、short、char、int、integer、enum枚举类型,在JDK7后,支持string类型。
public void test(String str) { switch (str) { case "abc": System.out.println("abc"); break; case "def": System.out.println("def"); break; case "ghi": System.out.println("ghi"); break; default: System.out.println("default"); } }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 使用Instruments中的Leaks检测内存泄露
- 下一篇: 中文乱码,试一试Base64