# 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


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


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

# Type arguments on method invocation parameters


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


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

Use a Java Refactoring Tool

No license required

You can review this refactoring on your code without a license by installing jSparrow to your Eclipse IDE. Install the plug-in from Eclipse IDE: Eclipse Marketplace.

System-wide Refactoring

Do you want to automate this refactoring (and many more) to your system-wide code? The automatic application of this system-wide refactoring can be unlocked by acquiring your jSparrow license.

a drawn cute bird pointing at a graph that shows positive results

# Properties

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