Get the interface name from the implementation class

后端 未结 2 1708
醉梦人生
醉梦人生 2020-12-20 15:44

Example :

List list = new ArrayList();
//This would give me the class name for the list reference variable.
list.getClass().getSi         


        
2条回答
  •  佛祖请我去吃肉
    2020-12-20 16:21

    Using Reflection you can invoke the Class.getInterfaces() method which returns an Array of Interfaces that your class implements.

    list.getClass().getInterfaces()[0];
    

    To get just the name

    list.getClass().getInterfaces()[0].getSimpleName();
    

提交回复
热议问题