例 :
List<String> list = new ArrayList<String>();
//This would give me the class name for the list reference variable.
list.getClass().getSimpleName();
list
参照変数からインターフェイス名を取得したい。それを行う方法はありますか?
Reflectionを使用すると、クラスが実装するClass.getInterfaces()
を返すメソッドを呼び出すことができます。Array of Interfaces
list.getClass().getInterfaces()[0];
名前だけを取得するには
list.getClass().getInterfaces()[0].getSimpleName();
Class aClass = ... //obtain Class object.
Class[] interfaces = aClass.getInterfaces();