Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make checkstyle require the Java 7 Diamond operator

Is it possible to make checkstyle require java 7 formatting of the diamond operator? I want to ensure my codebase consistently uses the new Java 7 style, i.e.:

List<String> items = new LinkedList<>();

instead of the older:

List<String> items = new LinkedList<String>();
like image 853
Jay Avatar asked May 21 '13 07:05

Jay


1 Answers

Take a look at this.

One of the users is complaining about a bug in the diamond operator grammar:

  List list = new ArrayList<>();
  throws an error:unexpected token: >

This bug report was closed thanks to a patch that adds support for Java 7.

According to the page, one of the features added was:

4) Diamond Generics: In presence of a diamond, the AST looks like:

+--TYPE_ARGUMENTS
|
+--GENERIC_START
+--GENERIC_END

Download link for the patch.

like image 147
aran Avatar answered Oct 12 '22 23:10

aran