我有两个枚举类,比如Enum1和Enum2:
enum Enum1 {ONE, TWO, THREE}
enum Enum2 {FOUR, FIVE}
Run Code Online (Sandbox Code Playgroud)
我有一个像这样的方法:
public <E extends Enum<E>> method (E arg) {
switch (arg) { // Here is the compile error -- Cannot switch
// on a value of type E. Only convertible int
// values, strings or enum variables are permitted
// (And of course, all the cases are incorrect
// because the enum set is unknown)
case ONE:
// do something
case TWO:
// do something
case THREE:
// do something …Run Code Online (Sandbox Code Playgroud)