Java中的枚举作为泛型类型在枚举中

14 浏览
0 Comments

Java中的枚举作为泛型类型在枚举中

我正在尝试在抽象类中创建一个抽象方法,该方法以我的自定义枚举作为参数。但是我也希望该枚举是通用的。

所以我这样声明了它:

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)

我想知道是否有可能不使用我的解决方法来解决这个问题?

0