Can someone explain me, why this cast is unchecked. It should be guaranteed that type T
is always derived from Base
and so the cast from T
to Base
should not be unchecked.
abstract class Base
{
private static final Map<Class<? extends Base>, Consumer<Base>> _CONSUMERS = new HashMap<>();
@SuppressWarnings( "unchecked" )
public static <T extends Base> void addConsumer( Class<T> clazz, Consumer<T> consumer )
{
_CONSUMERS.put( clazz, (Consumer<Base>) consumer );
}
}