如何利用java反射,获取属性接口的具体类

2025-04-14 21:55:12
推荐回答(2个)
回答1:

你可以这么写:
class BodyImpl implements Body{
//do something
public static void main(String[] args) {
Type[] interfaces = BodyImpl.class.getInterfaces();
ParameterizedType firstInterface = (ParameterizedType) interfaces[0];
Class c = (Class) firstInterface.getActualTypeArguments()[0];
System.out.println(c.getName()); // prints "AtomEntry"
}
}

就得到你所要的接口参数了!

回答2:

Java反射-属性操作