Created
November 26, 2012 15:46
-
-
Save zaki50/4148874 to your computer and use it in GitHub Desktop.
親クラスの型パラメータに指定されている方の情報を取得するコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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