Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 665
Pavlus Avatar asked Apr 22 '26 01:04

Pavlus


1 Answers

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.

like image 73
Chetan Kinger Avatar answered Apr 26 '26 05:04

Chetan Kinger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!