JDK7版本特性
2019-04-24 / JAVA / 989 次围观 / 0 次吐槽 /1.二进制字面量
System.out.println(0b1000);
2.数字字面量可以出现下划线
System.out.println(1000_0000);
3.switch 语句可以用字符串
String s = "A"; switch (s) { case "A": break; case "B": break; default: break; }
4.泛型简化,菱形泛型
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
5.异常的多个catch合并,每个异常用或|
try{ int i = 10 / 0;//算术异常 int[] arr = null; System.out.println(arr[0]);//空指针异常 }catch (ArithmeticException | NullPointerException e) { }
6.try-with-resources 语句 //这样写不用关流
try( FileInputStream fis = new FileInputStream("a.txt"); ){ fis.read(); }
Powered By Cheug's Blog
Copyright Cheug Rights Reserved.