Can Java 10 compiled classes run on 9?

See the English answer > can Java 8 code be compiled to run on Java 7 JVM? 5

Is my hypothesis correct?

Solution

This has nothing to do with Java 10; The rules are the same as before

In each java version, the class file version number is incremented You can run older class files on newer Java runtimes (you can run files compiled under Java 1.0 on Java 10 20 years ago!), However, newer class files have never been run at real runtime Java 10 has not changed

However, if you do not use newer features introduced since this release, you can compile classes to make them run on older versions This is usually done by the - source and - target switches:

// Run this on Java 8
javac -source 6 -target 6 Foo.java

And you will get the class files that will run on Java 6 and later (the source version cannot be greater than the target version.) It was recently replaced with a more comprehensive – release option:

javac --release 9

This not only means - source 9 and - target 9, but also the compiler will prevent you from using the JDK function introduced after 9

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>