Search code examples
java-8backwards-compatibility

Using default interface method from SPI in versions prior to Java 8


Is it possible to use default method implementation from interface, contained in library compiled with JDK8+, by code that will be compiled with JDK versions 5-7?

If yes, what are nuances that I should be aware of while implementing such interface?


Solution

  • The Compatibility Guide for JDK-8 states this :

    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.

    So the answer is no since you shouldn't be able to run/compile your Java SE 7 code that uses Java SE 8 compiled classes/jars in the first place.