Affects PMD Version: 7.18.0
Rule: UseDiamondOperator
Description:
Guice's TypeLiteral exists to capture type information. It forces you to create a subclass and thereby captures the generic type information for use at runtime. Removal of the type information by using the diamond operator changes the behaviour of the code, so PMD should not generate a warning and a suggestion to remove the type information and use the diamond operator.
Code Sample demonstrating the issue:
import com.google.inject.TypeLiteral;
protected Map<Key<?>, Object> computeBindings() {
return Map.of(
Key.get(new TypeLiteral<Optional<Long>>() {}, BusinessId.class),
Optional.of(businessIdProvider.get()));
}
Expected outcome:
PMD should allow the TypeLiteral to have the type information without generating a warning.
Running PMD through: Other: PMD plugin in IntelliJ
Affects PMD Version: 7.18.0
Rule: UseDiamondOperator
Description:
Guice's TypeLiteral exists to capture type information. It forces you to create a subclass and thereby captures the generic type information for use at runtime. Removal of the type information by using the diamond operator changes the behaviour of the code, so PMD should not generate a warning and a suggestion to remove the type information and use the diamond operator.
Code Sample demonstrating the issue:
Expected outcome:
PMD should allow the TypeLiteral to have the type information without generating a warning.
Running PMD through: Other: PMD plugin in IntelliJ