Oracle的官网:http://docs.oracle.com/javase/7/docs/index.html
该地址是java7的API文档:
下面选择其中的★部分说说:英语之外的文字是我个人的看法,欢迎大家多交流交流~
Java Programming Language
The following enhancements have been added to the Java language:
Binary Literals
Underscores in Numeric Literals
★Strings in switch Statements(字符串在switch 语句)
★Type Inference for Generic Instance Creation(泛型实例的类型推断)
Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods
The try-with-resources Statement
Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking
Java Virtual Machine
第一个:★Strings in switch Statements
In the JDK 7 release, you can use a String object in the expression of a switch statement:
public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) {
String typeOfDay;
switch (dayOfWeekArg) {
case "Monday":
typeOfDay = "Start of work week";
break;
case "Tuesday":
case "Wednesday":
case "Thursday":
typeOfDay = "Midweek";
break;
case "Friday":
typeOfDay = "End of work week";
break;
case "Saturday":
case "Sunday":
typeOfDay = "Weekend";
break;
default:
throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg);
}
return typeOfDay;
}
通过上面的例子可以看出,Switch语句中可以放入一个String对象了。
第二个:★Type Inference for Generic Instance Creation(泛型实例的类型推断)
举个例子:
In Java SE 7, you can substitute the parameterized type of the constructor with an empty set of type parameters (<>):
java 7中我们可以写:
Map<String, List<String>> myMap = new HashMap<>();
注意:右边的<>中不一定要写了,可以空着,但是7之前的版本如果这样写,编译时会报错的
还有很多新特性,找到源头了,文档就多看啦。现在网上翻译工具很多,虽然是英语的,但也应该沉下心来看啊,希望我的回答能帮到楼主^_^ |