我正在尝试在抽象类中创建一个抽象方法,该方法将我自己的Enum作为参数。但我也希望Enum是通用的。
所以我宣布它是这样的:
public abstract > void test(Enum command);
在实现中,我已经知道了那个:
public enum PerspectiveCommands {
PERSPECTIVE
}
并且方法声明变为:
@Override
public > void test(Enum command) {
}
但如果我这样做:
@Override
public > void test(Enum command) {
if(command == PerspectiveCommands.PERSPECTIVE){
//do something
}
}
我没有访问带有错误的PerspectiveCommands.PERSPECTIVE:
cannot find symbol symbol: variable PERSPECTIVE location: class Enum where PerspectiveCommands is a type-variable: PerspectiveCommands extends Enum declared in method test(Enum)
我做了一个像这样的解决方法:
public > byte[] executeCommand(Enum 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;
}
}
但我想知道是否有可能不通过我的解决方法?