New language features in Java 7

Posted on 25th November 2009 by Nio in Java, 程序人生 - Tags:

New language features in Java 7

I’m just back from the Devoxx conference in Antwerp. An update was given on the new language changes that will be in Java 7. The JDK currently has a release date of September 2010.

Here are 7 of the new features that have been completed:

* Language support for collections
* Automatic Resource Management
* Improved Type Inference for Generic Instance Creation (diamond)
* Underscores in numeric literals
* Strings in switch
* Binary literals
* Simplified Varargs Method Invocation

很多特性都非常有意思,比如:


List<String> list = new ArrayList<String>();
list.add("item");
String item = list.get(0);

Set<String> set = new HashSet<String>();
set.add("item");

Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key", 1);
int value = map.get("key");

可以变为:


List<String> list = ["item"];
String item = list[0];

Set<String> set = {"item"};

Map<String, Integer> map = {"key" : 1};
int value = map["key"];

最有意思的是数字:


int one_million = 1_000_000;

:)

No Comments »

No comments yet.

Leave a comment