-2

What is purpose of re-specifying the type on the right / constructor side of a Java Collection declaration + instantiation?

For example, how is

List<MyClass> a = new ArrayList<MyClass>();

different / better / worse than

List<MyClass> a = new ArrayList<>();

My understanding is the the second form became legal in Java 7, but I still see a lot of examples in Java 7 and 8 where the first form is used.

yokeho
  • 177
  • 1
  • 7
  • Thanks @Tunaki. I did lot of searching on stack overflow for an answer before posting, but did not know/use the term 'diamond operator'. Had not heard that terminology before. – yokeho Mar 05 '17 at 19:20

1 Answers1

0

It is not worse or different. It is the same.

A new and easy way introduced by compiler to reduce human effort of defining of type.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307