1:
private List<String> blacklist = new ArrayList<String>();
2:
private List<String> blacklist = new ArrayList<>();
Are there any advantages using the first or the second one in compile time or performance in nanoseconds?
1:
private List<String> blacklist = new ArrayList<String>();
2:
private List<String> blacklist = new ArrayList<>();
Are there any advantages using the first or the second one in compile time or performance in nanoseconds?
Both statements are semantically the same.
The 2nd example is using Diamond operator from Java 7 and so will be a little bit slower at compile time. At runtime they will have exactly the same performance as the generics information will be completely removed.
There is no difference. In the second case, the compiler infers the generic type of the ArrayList
.