简体   繁体   中英

How to auto generate Java 8 code in eclipse

How can I generate Java 8 specific code in eclipse IDE. For example using collections, on pressing CNTL + ENTER ; instead of generating following

 Collection<String> list = new ArrayList<String>();

it should generate

 Collection<String> list = new ArrayList<>();

NOTE: However CNTL + 1 does convert the anonymous interface to lambda expression.

You should choose the correct JRE System Library for your project and the autocompletion will change accordingly to the Java version used.

I have created a project named test-java-1.6 and I have verified that the Java autocomplete does not support diamond operator because of old java version.

The autocomplete behaviour changed immediately after the Java version update.

Here how to specify the java execution environment:

Java项目的属性

And how to change it to a newer version, here you should choose JavaSE-1.8

编辑资料库

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM