在java中获取SuperInterfaces

pro*_*ewb 8 java interface class

我一直试图这样做很长一段时间,似乎无法获得所需的输出.

我想做的是有一个班级名称 java.util.Vector

得到:

  • 直接实现的接口if java.util.Vector.
  • 由超类直接实现的接口.
  • 并且,传递上,这些接口的所有超接口.

任何帮助,将不胜感激.

Joh*_*sen 0

虽然 java.util.Vector 不是一个接口,因此您无法使用接口扩展它,但您可以做的是使用像Reflections这样的库来适应这些类型的功能。 反射允许您扫描类路径并查询一组条件,例如实现或扩展给定类/接口的条件。我已经在几个需要扫描接口实现和带注释的类的项目中成功使用了它。

这是明确的链接: http: //code.google.com/p/reflections/

此外,如果您只是想找出类扩展/实现的类/接口,您可以通过 class 属性使用类反射 api。

以下是一些示例:

//get all public methods of Vector
Vector.class.getMethods();
//get all methods of the superclass (AbstractList) of Vector
Vector.class.getSuperclass().getMethods();
//get all interfaces implemented by Vector
Vector.class.getInterfaces();
Run Code Online (Sandbox Code Playgroud)