获取类的所有(派生)接口 [英] get all (derived) interfaces of a class
本文介绍了获取类的所有(派生)接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
java.lang.Class.getInterfaces
返回所有直接实现的接口,即不会遍历类树以获取所有父类型的所有接口。例如,层次结构
java.lang.Class.getInterfaces
returns all directly implemented interfaces ie doesn't walk the class tree to get all interfaces of all parent types. eg For example the hierarchy
public interface A {}
public interface B {}
public interface C extends B {}
public class Foo implements A {} // Foo.class.getInterfaces() returns [A]
public class Bar implements C {} // Bar.class.getInterfaces() returns [C], note B is not included.
Bar
我想要 [B,C]
,但对于任意树深度。
For Bar
I would like to get [B, C]
, but for any arbitrary tree depth.
我可以自己写这个,但我是确定必须存在已经存在的库,任何想法?
I could write this myself, but I'm sure a library must exist that does this already, any ideas?
推荐答案
Apache Commons Lang 有你需要的方法: ClassUtils.getAllInterfaces
Apache Commons Lang has method you need: ClassUtils.getAllInterfaces
这篇关于获取类的所有(派生)接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文