You can replace the type arguments required to invoke the constructor of a generic class with an empty set of type parameters (
<>
) as long as the compiler can infer the type arguments from the context. This pair of angle brackets is informally called the diamond.
For example, consider the following variable declaration:
Map<String, List<String>> myMap = new HashMap<String, List<String>>();
In Java SE 7, you can substitute the parameterized type of the constructor with an empty set of type parameters (
<>
):Map<String, List<String>> myMap = new HashMap<>();
http://www.eclipse.org/jdt/ui/r3_8/Java7news/whats-new-java-7.html
No comments:
Post a Comment