Diamond operator is used to infer the generic type from
the declaration.
Example
List<Integer> list = new ArrayList<> ()
HelloWorld.groovy
List<Integer> intList = new ArrayList<> () List<String> strList = new ArrayList<> () intList.add(2) intList.add(3) intList.add(5) strList.add('India') strList.add('Sri Lanka') println intList println strList
Output
[2, 3, 5]
[India, Sri Lanka]
No comments:
Post a Comment