Let's say I want to create a standard project implementation, so I'm going to create a framework reusable by next projects to be developed.
Imagine there is a constraint on java version:
What are the rules that need to be followed in order to be able to build a framework that should work with multiple java version?
idk, something like
creating the framework with the lowest java version, minimize the dependencies on newer language features or APIs that may not be available in older Java versions.
I did not find much on that, hope it's not a stupid question, any good resources to understand more about creating generic frameworks that can be easily reused will be really appreciated!
creating the framework with the lowest java version, minimize the dependencies on newer language features or APIs that may not be available in older Java versions.
Well, yes. That's stating the obvious: If the library has to work with a project that is on java 8, obviously that library cannot use java9+ in any way: No java9+ features (no --source 9
/ --release 9
), no java9+ class files (--target 9
/ --release 9
), no use of any API whose @since
flag in its java doc reads java9 or higher, and no dependency on any library which isn't itself compatible with java8 and below.
Starting in.. java9? It's been in there for a while, but, jars can ship with multiple copies of the same class file, tailored to each JDK release. This is called the Multi-release JAR system. This feature is extremely rarely used, and using this feature is a maintenance nightmare (goooood luck testing all this; the usual java tooling (maven, gradle, junit, you name it) aren't designed to let you test the same code on many different JDK releases), and generally there's no point to it: Either the API in the java version you can't use because it is too recent is a convenience, and there is no benefit making a version that does not use it, as well as one that does use it - just build the one that does not. Or, it's a feature that doesn't exist until then (say, new file API to, say, make a hard link, something introduced in java.nio.file
API that simply wasn't available in the old java.io
package), and thus, you cannot make a library that 'works' on the java release that doesn't ship with it.
Note that java 8 has been end of lifed.