-1

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?

Bob
  • 1,201
  • 1
  • 9
  • 22

2 Answers2

2

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.

Crazyjavahacking
  • 9,343
  • 2
  • 31
  • 40
0

There is no difference. In the second case, the compiler infers the generic type of the ArrayList.

Andy Turner
  • 137,514
  • 11
  • 162
  • 243