在 Java 8 之前的版本中使用来自 SPI 的默认接口方法
Using default interface method from SPI in versions prior to Java 8
是否可以通过将使用 JDK 版本 5-7 编译的代码,使用包含在使用 JDK8+ 编译的库中的接口的默认方法实现?
如果是,在实现此类接口时我应该注意哪些细微差别?
JDK-8 的 Compatibility Guide 指出:
Java SE 8 is binary-compatible with Java SE 7 except for the incompatibilities listed below. Except for the noted incompatibilities, class files built with the Java SE 7 compiler will run correctly in Java SE 8. Class files built with the Java SE 8 compiler will not run on earlier releases of Java SE.
The Java class file format has been updated for the Java SE 8 release.
The class file version for Java SE 8 is 52.0 as per the JVM Specification. Version 52.0 class files produced by a Java SE 8 compiler cannot be used in earlier releases of Java SE.
所以答案是 否 因为你不应该 run/compile 你的 Java SE 7 使用 Java SE 8 的代码首先编译 classes/jars。
是否可以通过将使用 JDK 版本 5-7 编译的代码,使用包含在使用 JDK8+ 编译的库中的接口的默认方法实现?
如果是,在实现此类接口时我应该注意哪些细微差别?
JDK-8 的 Compatibility Guide 指出:
Java SE 8 is binary-compatible with Java SE 7 except for the incompatibilities listed below. Except for the noted incompatibilities, class files built with the Java SE 7 compiler will run correctly in Java SE 8. Class files built with the Java SE 8 compiler will not run on earlier releases of Java SE.
The Java class file format has been updated for the Java SE 8 release.
The class file version for Java SE 8 is 52.0 as per the JVM Specification. Version 52.0 class files produced by a Java SE 8 compiler cannot be used in earlier releases of Java SE.
所以答案是 否 因为你不应该 run/compile 你的 Java SE 7 使用 Java SE 8 的代码首先编译 classes/jars。