It's my guess that you're confusing FOO as a subtype as MyClass when it is in fact an instance.
With 'normal' generics you specify the type the placeholder will be:
public class GenericClass <T extends Object> { // a bit contrived here
private T generic;
}
which is instantiated
GenericClass<String> gen = new GenericClass<>(); // String is a subclass of Object
this is then compiled to
public class GenericClass {
private String generic;
}
Notice there is no value for the String. There is no String instance.
To do this we either need a setter or constructor:
public class GenericClass<T extends Object> {
private T generic;
public GenericClass(T generic) {
this.generic = generic;
}
}
GenericClass<String> gen = new GenericClass<>("Passing in a String because T was a String");
or
GenericClass<Integer> gen2 = new GenericClass<>(2); // T is integer so we can only pass integers - 2 will be the instance.
So for the Enum as a generic type we're stating the type which is MyType. The value would be FOO, so again we'd need either a setter or a constructor:
public class MyClass<T extends MyTypes> {
private T theType;
public MyClass(T theType) {
this.theType = theType;
}
}
and to make sure we're have a FOO instance we pass it in to the constructor
MyClass<MyTypes> myInstanceWithFoo = new MyClass<>(MyTypes.FOO);
Hope this makes sense.