0

I've see that since java 1.5 or maybe a later version, you can initialize java collection leaving generics blank, i.e. using <> instead of writing out the whole < A,B >. but I can't find the official documents on this, and I'm wondering whether this has any benefits (or maybe I'm not remembering this correctly, in which case do point out the correct form). Thank you.!

DanSoren
  • 173
  • 2
  • 9

2 Answers2

3

It's called the diamond operator. It was introduced in Java 1.7.

The benefit is just that you need to write less code.

Compare

List<Map<String, Integer>> list = new ArrayList<Map<String, Integer>>();

to

List<Map<String, Integer>> list = new ArrayList<>();
Paul Boddington
  • 37,127
  • 10
  • 65
  • 116
0

What you're looking for is called the diamond operator. It was introduced in Java 7.

Ken Wayne VanderLinde
  • 18,915
  • 3
  • 47
  • 72