Aleydin Karaimin
Aleydin Karaimin

Reputation: 964

Java compatibility - import classes built with newer java

I am working on a project in which some of the subprojects need to be build with older JDK. However, some of the classes in the same subproject imports classes from third party jar (another subproject) built with newer JDK. My question is it possible to import this classes, if the runtime JDK is the newer one. For example: Let's assume that, my project is build with JDK 1.6. In one of the classes I need to import class from third party jar (build with newer JDK - 1.8), I will create object and call method (nothing special). Then I will run my project witn JDK 1.8. Is the whole scenario possible?

Upvotes: 2

Views: 111

Answers (1)

Egor Zhuk
Egor Zhuk

Reputation: 276

As far as I know you have no options other then compile all your code with a higher language level. But... If you really can't do it by any wierd reason, you can implement a hack. You can implement a Runnable that uses your tricky dependencies. Do it in a separate project, compile it with a newer java, provide the jar and inject the Runnable by the DI you use in your project. Then just call run in your legacy code.

Upvotes: 1

Related Questions