2

假设我有

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???

4

1 回答 1

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]

于 2017-06-16T14:19:49.750 回答