How Spring achieves compatibility with Java 6, 7 and 8
As of Spring Framework 4.0, Java 8 is supported as a first-class citizen and we've seen some confusion in the Spring community since then. How do we manage to support Java 8 and remain compatible with Java 6 and Java 7 after all? This blog post provides some insight into how we're handling this within the framework codebase.
Java 8 language features vs. Java 8 APIs
First, a distinction must be made between using new language features and new APIs in a given Java generation such as Java 8. If a class uses a Java 8 language feature such as a lambda expression, it has to be compiled with -source 1.8 -target 1.8 and therefore the whole compilation unit will only work on Java 8+. However, if a particular class in a library optionally uses a new Java 8 interface such as java.util.stream.Stream, the library can still run on a previous Java generation as long as it is being compiled with e.g. -source 1.6 -target 1.6 - and as long as the use of that particular …