我有五个枚举案例,如下所示:
public enum Answers{
A(0), B(1), C(2), D(3), E(4);
Answers(int code){
this.code = code;
}
protected int code;
public int getCode(){
return this.code;
}
}
除了由不同的“代码”和枚举器组成之外,它们几乎都是相同的。我现在有下面这个类,其中泛型是枚举的扩展,但是,我需要能够使用getCode()
,它只在我的枚举中,而不是基本枚举。
public class test<T extends Enum>{
public void tester(T e){
System.out.println(e.getCode()); //I want to be able to do this,
//however, the basic enum does don't
//have this method, and enums can't extend
//anything.
}
}
谢谢