Suggests removing impotant cast - result does not compile

sonarlint
java

(Joachim Lous) #1

The code below triggers S1905 (observed in SonarLint v4.0.0.2916)
It suggest I “Remove this unneccessary cast to T2”.
If I do the code does not compile.

public class MapByName<T1 extends Enum, T2 extends Enum>
    implements EnumMapper<T1, T2> {

    private final Class<T2> destClass;

    public MapByName(Class<T2> destClass) {
        this.destClass = destClass;
    }

    @Override
    public T2 map(T1 src) {
        return (T2) Enum.valueOf(destClass, src.name());
    }
}