What is the point of the diamond operator () in Java?

The diamond operator in java 7 allows code like the following:

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

However in Java 5/6, I can simply write:

List<String> list = new LinkedList();

My understanding of type erasure is that these are exactly the same. (The generic gets removed at runtime anyway).

Why bother with the diamond at all? What new functionality / type safety does it allow? If it doesn’t yield any new functionality why do they mention it as a feature? Is my understanding of this concept flawed?

7 s
7

Leave a Comment