参考:http://radar.oreilly.com/2011/09/java7-features.html
语法增强:
1.方块caozuofu.html" target="_blank">操作符
原:
Map<String, List<Trade>> trades = new TreeMap<String, List<Trade>> ();
现:
Map<String, List<Trade>> trades = new TreeMap <> ();
2.switch终于可以使用String类型了
String status = t.getStatus();
switch (status) {
case NEW:
break;
case EXECUTE:
break;
case PENDING:
break;
default:
break;
}
3.自动关闭资源
不需要在finally写close()。
try (FileOutputStream fos = new FileOutputStream("movies.txt");
DataOutputStream dos = new DataOutputStream(fos)) {
dos.writeUTF("Java 7 Block Buster");
} catch (IOException e) {
}
4.更直观的数字显示
int thousand = 1_000;
等价于
int thousand = 1000;
5.增强的异常处理
一个catch可以抓多个异常。
public void newMultiCatch() {
try {
methodThatThrowsThreeExceptions();
} catch (ExceptionOne | ExceptionTwo | ExceptionThree e) {
// log and deal with all Exceptions
}
}