如果我使用反射来获得扩展公共类的类,那么列表是否也包含所有递归继承的类?

时间:2017-06-16 11:58:39

标签: java inheritance google-reflections

假设我有

class A{}
class B extends A{}
class C extends A{}
class D extends C{}
class E extends B{}

我有以下代码

Reflections reflections = new Reflections();    
Set<Class<? extends A>> classes = reflections.getSubTypesOf(A.class);

集合classes是否包含类DE ???

1 个答案:

答案 0 :(得分:0)

import java.util.Set;

import org.reflections.Reflections;

public class Test {
    public static void main(String[] args) throws java.lang.Exception {
        Reflections reflections = new Reflections();
        Set<Class<? extends A>> classes = reflections.getSubTypesOf(A.class);
        System.out.println(classes);
    }
}

class A {
}

class B extends A {
}

class C extends A {
}

class D extends C {
}

class E extends B {
}

输出:[class C, class D, class B, class E]