Skip to main content

Command Palette

Search for a command to run...

The diamond operator ("<>") should be used (squid:S2293)

Updated
1 min read
The diamond operator ("<>") should be used (squid:S2293)
S

I love learning about technology and sharing that with others

This rule is applicable for java version 7 or Above

Java 7 introduced the diamond operator (<>) to reduce the verbosity of generics code.

For instance, instead of having to declare a List's type in both its declaration and its constructor, you can now simplify the constructor declaration with <>, and the compiler will infer the type.

Noncompliant Code Example

List<String> strings = new ArrayList<String>();  
Map<String,List<Integer>> map = new HashMap<String,List<Integer>>();

Compliant Solution

List<String> strings = new ArrayList<>();
Map<String,List<Integer>> map = new HashMap<>();
5 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)