What is the proper way of giving generics?

We have been using java generics heavily in our application.

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

In the above line i have not given 'String' at the right side, Is that correct? It is giving error in my eclipse but it is not showing error in my collegues eclipse, what might be the reason?

Jon Skeet
people
quotationmark

This is the "diamond operator" (not really an operator) feature in Java 7, which allows type arguments on a constructor call to be inferred from the context in which the result is used.

It's valid for Java 7, but not before. You should check your Java settings in Eclipse and compare them with those of your colleague. My guess is that your source version isn't 7 whereas his is. The setting is on the Window / Preferences / Java / Compiler tab, or just the "Java Compiler" part of project properties, if you have project-specific settings. A compliance level of 1.7 will enable the Java 7 features.

See Oracle's page on "type inference for generic instance creation" for more details.

people

See more on this question at Stackoverflow