Jay
Jay

Reputation: 20136

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>();

Upvotes: 7

Views: 1005

Answers (1)

aran
aran

Reputation: 11880

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.

Upvotes: 1

Related Questions