[英]Get the interface name from the implementation class
范例:
List<String> list = new ArrayList<String>();
//This would give me the class name for the list reference variable.
list.getClass().getSimpleName();
我想從list
引用變量中獲取接口名稱。 有沒有辦法做到這一點?
使用反射,您可以調用Class.getInterfaces()
方法,該方法返回您的類實現Array of Interfaces
。
list.getClass().getInterfaces()[0];
為了得到名字
list.getClass().getInterfaces()[0].getSimpleName();
Class aClass = ... //obtain Class object.
Class[] interfaces = aClass.getInterfaces();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.