3

In Collections I've found the following:

@SuppressWarnings("unchecked")
public static final List EMPTY_LIST = new EmptyList<>();

I really can't find any reason to use:

new EmptyList<>()

here instead of:

new EmptyList()

as it would be for java < 1.7.

Is there any difference between this approach?

krems
  • 749
  • 6
  • 14

1 Answers1

2

If you are concerned only about <> operator then you should see What is the point of the diamond operator in Java 7?.

Regarding EMPTY_LIST: Either you do :

@SuppressWarnings("rawtypes")
List list = Collections.EMPTY_LIST;

OR Something like:

List<String> s = Collections.emptyList();

The reason to use <> operator is maintaining compile time checking for raw types. The above links describes that well.

Community
  • 1
  • 1
Raju Singh
  • 137
  • 1
  • 9
  • 1
    I think he knows what's the point of diamond operator. He is just asking what's the point behind it in the scenario he has shown. – Adam Dyga Dec 05 '13 at 15:38