如何使用Java1.8编译1.6JVM可运行的class文件
大家讲道理
大家讲道理 2017-04-18 10:51:37
0
2
504

想在项目中使用jdk1.8的一些新特性去开发,但是编译出来的class如果在低版本的java环境中运行会出现class版本不匹配的问题。如图

那么想请教下,Spring中是如何做到通过1.8编译,而只要求jdk版本大于1.6就可以的?

  • 版本要求

  • spring build.gradle文件

希望大神可以解答下,目前没搞明白比较困惑

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
Ty80

You can take a lookjavac的参数,里面有两个sourcetarget

 -source <版本>               提供与指定版本的源兼容性
 -target <版本>               生成特定 VM 版本的类文件

The compiled class file version can be changed by setting these two parameters.
For examplejavac -source 1.6 -target 1.6 Hello.java

大家讲道理

To use the new features of 1.8, you can introduce third-party jar packages. Still compiled using jdk1.6.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!