Recently, I saw the following constructor call:
Set<String> s = new HashSet<>();
I was surprised that one can call the constructor of the generic class HashSet
with empty parentheses <
and >
. What does this mean?
Recently, I saw the following constructor call:
Set<String> s = new HashSet<>();
I was surprised that one can call the constructor of the generic class HashSet
with empty parentheses <
and >
. What does this mean?
Since you've already declared what type of value (String in this case) the Set will hold, repeating it is redundant.
this is diamond syntax, introduced since java7
reference: https://dzone.com/articles/java-7-do-we-really-need