0

Consider this class structure.

class Class1<T> {
    Class2<T> field1;
}

If I have a ParameterizedType instance representing Class1<String> through reflection, how can I get/create a ParameterizedType instance representing Class2<String>?

2 Answers 2

1

ParameterizedType is an interface. Simply write a class that implements it (or copy some existing implementation from the Internet) so that its methods return what you want.

Sign up to request clarification or add additional context in comments.

Comments

0

In its current state the reflection API allows for (limited) inspection of generic type information. Since one could not leverage the newly constructed ParameterizedType there is little point in allowing its construction in the first place.

If you are building an API accepting ParameterizedTypes and need users to construct their own, you might consider switching to guava's TypeToken-Class instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.