Я пытаюсь создать абстрактный метод в абстрактном классе, который принимает мой собственный Enum в качестве аргумента. Но я хочу также, чтобы Enum был общим.
Итак, я объявил это так:
public abstract <T extends Enum<T>> void test(Enum<T> command);
В реализации у меня есть en enum как таковой:
public enum PerspectiveCommands {
PERSPECTIVE
}
и объявление метода будет выглядеть следующим образом:
@Override
public <PerspectiveCommands extends Enum<PerspectiveCommands>> void test(Enum<PerspectiveCommands> command) {
}
Но если я это сделаю:
@Override
public <PerspectiveCommands extends Enum<PerspectiveCommands>> void test(Enum<PerspectiveCommands> command) {
if(command == PerspectiveCommands.PERSPECTIVE){
//do something
}
}
У меня нет доступа к PerspectiveCommands.PERSPECTIVE
с ошибкой:
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>)
Я сделал обходной путь следующим образом:
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;
}
}
Но я хотел бы знать, возможно ли это пройти мимо моего обходного пути?