使用不同版本的JDK编译Java以及相同的目标和源版本是否保证相同的执行? [英] Does compiling Java with different versions of JDK and same target and source version guaranties same execution?

查看:505
本文介绍了使用不同版本的JDK编译Java以及相同的目标和源版本是否保证相同的执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将更新我们的CI系统,该系统从Java 7到Java 8创建构建。稍后我们希望将项目逐个迁移到Java 8。当然,我们希望能够为仍然使用Java 7的旧版本创建错误修复版本。

We are going to update our CI system that creates builds from Java 7 to Java 8. Later we would like to migrate projects to Java 8 one by one. Of course, we would like to be able to create bugfix releases for older versions that still use Java 7.

如果我们转移建筑,我们能否确定不会出现任何问题从JDK 7到JDK 8的相同源,目标版本和源版本?我们在没有任何问题的情况下对开发机器进行了测试。

Can we be sure that no issues will appear if we transfer building same source, target version and source version from JDK 7 to JDK 8? We did testing on development machines without any issues.

在此之前,我们还逐步将部署服务器从JRE 7更新到JRE 8.

Before that, we are also gradually updating deployment servers from JRE 7 to JRE 8.

请注意,我们希望在CI系统上保持单个Java JDK安装,否则会变得复杂。

Note that we would like to keep single Java JDK installation on CI system, it gets complicated otherwise.

使其更清晰:
我对相同的执行结果更感兴趣,而不是相同的字节码。如果我理解正确的话,相同的字节码只会确认第一个(在相同的JRE上运行)。

To make it more clear: I am more interested in same execution outcome, not so much about the same bytecode. Same bytecode would just confirm the first (running on same JRE), if I understand that correctly.

在我们运行所有部署之前,我们不会在代码中使用Java 8功能因此,兼容性不是问题。

We will not use Java 8 features in code until we have all deployments running on Java 8. So compatibility is not an issue.

推荐答案


使用不同版本的Java编译Java JDK和相同的目标和源版本产生相同的字节码?

Does compiling Java with different versions of JDK and same target and source version produce same bytecode?

没有保证。

实际上,使用相同编译器在相同硬件上使用相同选项从相同源代码创建的两个.class文件将具有相同的字节码,但由于嵌入式编译时间戳属性,文件可能仍然不同。

Indeed, two .class files created from the same source code using the same compiler with the same options on the same hardware will have the same bytecode, but the files may still be different because of embedded compilation timestamp attributes.

但是,如果你想比较名义上等效的字节码文件,这个Q& A提供了一些可能的线索:

However, if you wanted to compare notionally equivalent bytecode files, this Q&A offers some possible leads:

  • Is there a tool that we could use to compare two Jars at Binary/Byte code level?

我希望你发现Java 7生成的字节码与Java 8编译器,但这没关系。

I expect that you will find that there are some differences between the bytecodes generated by Java 7 and Java 8 compilers, but that this won't matter.

这篇关于使用不同版本的JDK编译Java以及相同的目标和源版本是否保证相同的执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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