Is there any way of using SomeClass.class as the generic type for a type?
For example I have an enum:
enum MyEnum {
FOO(String.class);
private Class fooClass;
private MyEnum(Class fooClass) {
this.fooClass = fooClass;
}
public Class getFooClass(){
return fooClass;
}
}
And then somewhere in my code:
List<MyEnum.FOO.getFooClass()> list = new ArrayList<>();
No. Generics are evaluated at compile time while the value of this call:
MyEnum.FOO.getFooClass()
is only known at runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With