What you're trying to do can work so long as E is parameterized in a type definition somewhere. For example:
Parameterized<E> pe = new Parameterized<E>();
This will not allow you to resolve E
since it's not part of a type definition. On the otherhand, this:
class StringE extends Parameterized<String> {}
or this:
Parameterized<String> ps = new Parameterized<String>(){};
will work since we're specifying the value of E as part of a type definition. To resolve the value of E
, you might use TypeTools (which I authored):
Class<?> stringType = TypeResolver.resolveRawArgument(Parameterized.class, ps.getClass());assert stringType == String.class;