Closed stokpop closed 2 days ago
I don't see the false positive in the pmd7 version. Seems to work fine. Pls check.
Yes, I cannot get the rule to fail, so should be good. Below AuthEnum
is ok, Auth
is not (does not implement Comparable).
import java.util.Map;
class Foo {
private enum AuthEnum {
A,B,C
}
private static class Auth {
public static Auth A;
public static Auth B;
public static Auth C;
}
private static final Map<AuthEnum, Func> settings =
Map.ofEntries(
Map.entry(AuthEnum.A, Func.A),
Map.entry(AuthEnum.B, Func.O),
Map.entry(AuthEnum.C, Func.V));
Enums (Auth) are used as keys: are Comparable already.
private static final Map<Auth, Func> settings = Map.ofEntries( Map.entry(Auth.A, Func.A), Map.entry(Auth.B, Func.O), Map.entry(Auth.C, Func.V));
BTW: use EnumMap instead in these cases?
Note: tricky when value is added to an enum: https://stackoverflow.com/questions/519788/why-is-compareto-on-an-enum-final-in-java