可以在Java 6 VM上编译Java 8代码库并在其上工作吗? [英] Can a Java 8 codebase be compiled and work on a Java 6 VM?

查看:153
本文介绍了可以在Java 6 VM上编译Java 8代码库并在其上工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Java 8编译的Java 8代码库是否可以在Java 6 VM上工作?

Will a Java 8 codebase that is compiled with Java 8 work on a Java 6 VM?

推荐答案

是的,但是如果您不使用Java 7和Java 8的功能...

Yes, but if you don't make use of features of java 7 and java 8 ...

如果代码库是使用较新的Java版本的功能编写的,则 没办法

If the codebase is written using features of newer java versions, then no there's no way to do it!

但是,如果要在Java 6上运行它们,则必须在编译源代码文件时设置Java 6合规性级别(使用-source 1.6 -target 1.6 javac参数),以使其与Java 6兼容.如上所示设置合规性,您将得到一个 UnsupportedClassVersionError :

However, if you want to run them on java 6 you have to set java 6 compliance level(with -source 1.6 -target 1.6 javac parameters) when you compile source code files, to make them compatible with java 6. If you don't set the compliance as shown above, you will get an UnsupportedClassVersionError :

java.lang.UnsupportedClassVersionError:Unsupported major.minor version XX.X

这篇关于可以在Java 6 VM上编译Java 8代码库并在其上工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆