重複の可能性:
リフレクションを使用して Java でジェネリック パラメーターの型を
取得する 実行時にクラスのジェネリック型を取得する
次のようなクラスがあるとします。
public class Foo<T, M> {
Pair<T, M> bar;
}
実行時に「T」と「M」が何であるかを判断する方法はありますか? 例えば
Foo<String, Integer> foo1 = new Foo<String, Integer>();
Foo<Integer, Boolean> foo2 = new Foo<Integer, Boolean>();
// what happens next?
ありがとう!