# Remove Explicit Type Argument

# Description

Since Java 7 the Diamond Operator (opens new window) (<>) can be used to simplify instance creation where generics are involved.

# Benefits

Applying this rule reduces clutter and improves readability.

# Tags

# Code Changes

# Type arguments on new instance creations

Pre

Map<String, List<String>> myMap = new HashMap<String, List<String>>();

Post

Map<String, List<String>> myMap = new HashMap<>();

# Type arguments on method invocation parameters

Pre

// Requires Java 8
List<GenericSample> result = foo.genericMethod(new ArrayList<GenericSample>(), input);

Post

// Requires Java 8
List<GenericSample> result = foo.genericMethod(new ArrayList<>(), input);

🛠️ Auto-refactor Available

You can auto-refactor this with jSparrow.
Drop this button to your Eclipse IDE workspace to install jSparrow for free:

Drag to your running Eclipse* workspace. *Requires Eclipse Marketplace Client

Need help? Check out our installation guide.

# Properties

Property Value
Rule ID DiamondOperator
First seen in jSparrow version 1.0.0
Minimum Java version 7
Remediation cost 1 min
Links