Prev Next

Java / Operators

Explain Diamond Operator in Java.

<> denotes the diamond operator. Purpose of the diamond operator is to simplify instantiation of generic classes.

For example, see the below.

List<Integer> myList = new ArrayList<Integer>(); 
//with the diamond operator we can write as below easily.

List<Integer> myList = new ArrayList<>(); 

The Diamond Operator reduces some of Java's verbosity surrounding generics by having the compiler infer parameter types for constructors of generic classes.

More Related questions...

Show more question and Answers...


Comments & Discussions