LoginSignup
1
0

More than 5 years have passed since last update.

インターフェースの型パラメータを取得する

Last updated at Posted at 2016-11-07

インターフェースの実装クラスで定義した、型パラメータを取得する方法です。

  • インタフェース

    
    public interface Foo<T> {
    }
    
  • 実装クラス

    
    public class Bar implements Foo<String> {
    }
    
  • 判定処理

    
    ParameterizedType type = (ParameterizedType) Bar.class.getGenericInterfaces()[0];
    Class<?> genericsClass = (Class<?>) type.getActualTypeArguments()[0];
    System.out.println(genericsClass);
    
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0