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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With