First of all, don't try to 'override' with static methods. It does not work the way you think it does - the 'overridden' static methods can still be accessed from the subclass in devious (accidental) ways. If you want overriding behavior, use local methods.
The warning is being generated because the Tiger
method signature is not compatible with what the super-class method promises - that any class <T>
chosen by the client can be decoded to, which is a very big, unfulfillable promise.
A better method would be:
abstract class AnimalTransformer<T extends Animal> {
public T decodeAnimalFromBytes(byte[] animalInBytes) {
return null;
}
public static byte[] encodeAnimalInBytes(T animal) {
return null;
}
}
class TigerTransformer extends AnimalTransformer<Tiger> {
public Tiger decodeAnimalFromBytes(byte[] animalInBytes) {
return new Tiger();
}
public byte[] encodeAnimalinBytes(Tiger tiger) {
return new byte[0];
}
}
This represents what you are trying to model more clearly - an AnimalTransformer
provides transformation methods for some subclass of Animal
, and it is up to the subclass, or anonymous implementation, to clarify which.