-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,171
  • 1
  • 8
  • 20

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
  • 8,777
  • 2
  • 30
  • 40
0

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

Andy Turner
  • 131,952
  • 11
  • 151
  • 228