class MyClass<E extends Enum<E>> {
private E myEnum;
public MyClass(E myEnum) {
this.myEnum = myEnum;
}
public E getMyEnum() { return myEnum; }
public void setMyEnum(E e) { myEnum = e; }
}
现在我有了这些:
Enum<?> someRandomEnum = // Retrieved from somewhere
MyClass<?> enumClassA = new MyClass<>(someRandomEnum); // Cannot infer type arguments
MyClass<?> enumClassB = new MyClass<Object>(someRandomEnum); // Obviously Object is not subclass of an enum
MyClass<?> enumClassC = new MyClass<? extends Enum<?>>(someRandomEnum); // Cannot instantiate the type MyClass<? extends Enum<?>>