有人可以帮我了解 jdk 版本在 org.reflections.Reflections jar 上的兼容性吗

can someone help me to know jdk version compatibility on org.reflections.Reflections jar

我是第一次使用Reflections.jar,所以想了解以下内容

1)根据https://github.com/ronmamo/reflections/blob/master/pom.xml,是用java1.7编译的,所以兼容java版本>=1.7
2) http://javarevisited.blogspot.ru/2012/07/when-class-loading-initialization-java-example.html

如果你在谈论这个https://github.com/ronmamo/reflections project then it find the classes in the order they appear in your classpath like the Java launcher would do. The way how classes are found and loaded is described here https://docs.oracle.com/javase/8/docs/technotes/tools/findingclasses.html

class 路径顺序中第一个 class 文件与完整的 class 名称相匹配。在下面找到一个小片段进行演示。

假定以下目录和文件

lib/annotations-2.0.1.jar
lib/guava-15.0.jar
lib/javassist-3.18.2-GA.jar
lib/reflections-0.9.9.jar
src/DummyInterface.java
src/Main.java
src1/DummyClass1.java
src2/DummyClass1.java

src/DummyInterface.java

package sub.optimal;
public interface DummyInterface {}

src/Main.java

import org.reflections.Reflections;
import sub.optimal.DummyInterface;
public class Main {
    public static void main(String[] args) throws Exception {
        Reflections reflections = new Reflections("sub.optimal");
        for (Class c : reflections.getSubTypesOf(DummyInterface.class)) {
            System.out.println("class: " + c.getCanonicalName());
            c.newInstance();
        }
   }
}

src1/DummyClass1.java

package sub.optimal;
public class DummyClass1 implements DummyInterface {
    static {
        System.out.println("touched DummyClass 1");
    }
}

src2/DummyClass1.java

package sub.optimal;
public class DummyClass1 implements DummyInterface {
    static {
        System.out.println("touched DummyClass 2");
    }
}

首先编译 classes,为了演示我们在不同位置创建 class 文件

javac -cp lib/* -d bin/ src/DummyInterface.java src/Main.java
javac -cp bin/:lib/* -d bin1/ src1/DummyClass1.java
javac -cp bin/:lib/* -d bin2/ src2/DummyClass1.java

在 class 路径中的 bin2/ 之前执行 Mainbin1/ 将在 bin1/[=31 中找到并加载 DummyClass1 =]

java -cp bin/:bin1/:bin2/:lib/* Main

输出

class: sub.optimal.DummyClass1
touched DummyClass 1

在 class 路径中的 bin1/ 之前执行 Mainbin2/ 将找到并加载 bin2/[=31 中的 DummyClass1 =]

java -cp bin/:bin2/:bin1/:lib/* Main

输出

class: sub.optimal.DummyClass1
touched DummyClass 2