No. There isn't. That's pretty much the definition of type erasure.
That said, there are some funky workarounds. You could explicitly look up the components of the pair, and ask their types. You could use the cool trick with anonymous inner classes that e.g. Guava's TypeToken
uses -- you can't determine the type of new Foo<String, Integer>()
at runtime, but you can determine the type of new Foo<String, Integer>() {}
at runtime -- note the anonymous inner class, which does retain the generic parameters specified for its superclass, namely Foo
. (Disclosure: I contribute to Guava.)
Frequently, the best solution of all is to avoid needing this information in the first place. There isn't a general cookbook for how to do this, but it's usually possible.
All that said, the only general-case solution to this need is to pass around the Class
metadata explicitly.