I'm trying to create an abstract method in a abstract class that takes my own Enum as argument. But I want also that that Enum will be generic.
So I declared it like that:
public abstract <T extends Enum<T>> void test(Enum<T> command); In the implementation, I have en enum as that one:
public enum PerspectiveCommands { PERSPECTIVE } and the method declaration becomes:
@Override public <PerspectiveCommands extends Enum<PerspectiveCommands>> void test(Enum<PerspectiveCommands> command) { } But if I do:
@Override public <PerspectiveCommands extends Enum<PerspectiveCommands>> void test(Enum<PerspectiveCommands> command) { if(command == PerspectiveCommands.PERSPECTIVE){ //do something } } I don't have access to the PerspectiveCommands.PERSPECTIVE with the error:
cannot find symbol symbol: variable PERSPECTIVE location: class Enum<PerspectiveCommands> where PerspectiveCommands is a type-variable: PerspectiveCommands extends Enum<PerspectiveCommands> declared in method <PerspectiveCommands>test(Enum<PerspectiveCommands>) I've made a workaround like this:
public <T extends Enum<T>> byte[] executeCommand(Enum<T> command) throws Exception{ return executeCommand(command.name()); } @Override protected byte[] executeCommand(String e) throws Exception{ switch(PerspectiveCommands.valueOf(e)){ case PERSPECTIVE: return executeCommand(getPerspectiveCommandArray()); default: return null; } } But I would like to know if it's possible to not pass by my workaround?