Use the Diamond Operator for Constructor Type Inference in Java
Description
The following code shows how to use the Diamond Operator for Constructor Type Inference.
With Diamond Operator we no long need to duplicate the generic parameter from the declaration.
Example
//from w w w . j a v a2 s . c o m
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Main {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
System.out.println(list);
List<Map<String, List<String>>> stringList = new ArrayList<>();
System.out.println(stringList);
}
}
The code above generates the following result.