Skip to content

Instantly share code, notes, and snippets.

@zaki50
Created November 26, 2012 15:46
Show Gist options
  • Save zaki50/4148874 to your computer and use it in GitHub Desktop.
Save zaki50/4148874 to your computer and use it in GitHub Desktop.
親クラスの型パラメータに指定されている方の情報を取得するコード
package org.zakky.typeparameter;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
abstract class Base<K, V> {
}
class Sub<V> extends Base<String, V> {
}
public class Main {
public static void main(String[] args) {
final Type genericSuperclass = Sub.class.getGenericSuperclass();
if (genericSuperclass instanceof ParameterizedType == false) {
return;
}
ParameterizedType type = (ParameterizedType) genericSuperclass;
for (Type t : type.getActualTypeArguments()) {
System.out.println(t.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment