JDK,JRE兼容JAR [英] JDK, JRE an JARs compatibility

查看:129
本文介绍了JDK,JRE兼容JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JDK和JRE源代码和二进制兼容性有所了解(例如这个),但不确定以下情况:

I know a bit about JDK and JRE source and binary compatibility (e.g. this and this), but not sure about the following situation:

考虑我有一个使用JDK5编译并在JRE6上运行的应用程序。它使用一些库(jar),它们也使用JDK5编译。

Consider I have an application which is compiled using JDK5 and runs on JRE6. It uses some libraries (jars) which are also compiled using JDK5.

现在我想用JDK6编译我的应用程序。在这种情况下运行时会出现什么新问题(特别是与旧罐子的兼容性)?我应该完全重新测试应用程序(触摸每个库)还是可以依赖于承诺的JDK / JRE兼容性?

Now I want to compile my application using JDK6. What new problems could arise in runtime in such a case (particularly, in compatibility with the "old" jars)? Should I fully retest the application (touch every library) or can rely on promised JDK/JRE compatibility?

推荐答案

通常如果您将JDK6的编译器选项设置为使用1.5源兼容性,则不会出现任何问题。但是有时并不总是如此

我记得曾经用1.5编译器编译1.4代码(使用1.4兼容性)。 ok(1.4二进制级别)但是应用程序由于有趣的转换而崩溃。

I remember once when compiling 1.4 code with 1.5 compiler (using 1.4 compatibility). The jars where ok (1.4 binary level) but the application crashed due to a funny conversion.

我们使用BigDecimal数字将一个整数作为参数传递给构造函数。 1.4版本只有一个构造函数从 double 1.5版本同时具有 int double 构造函数。因此,当使用1.4编译器进行编译时,会自动从 int 转换为 double ,但是使用1.5编译器时它检查了 int 构造函数已存在且未实现转换。然后当在1.4 JRE上使用完美的二进制兼容代码时,程序崩溃了 NoSuchMethodException

We used a BigDecimal number passing an integer as argument to the constructor. The 1.4 version had only a constructor from double but the 1.5 version had both, the int and the double constructors. So when compiling with 1.4 compiler made the automatic conversion from int to double, but with the 1.5 compiler it checked that the int constructor existed and did not realize that conversion. Then when using the perfect binary compatible code on 1.4 JRE the program crashed with a NoSuchMethodException.

我不得不承认这是一个奇怪的案例,但它是逻辑不起作用的案例之一。所以我的建议是,如果您计划编译旧版本的JRE,请尽可能使用目标版本JDK。

I have to admit that it was a strange case, but it is one of those cases where logic does not work. So my advice is if you plan to compile for older versions of JRE try to use the target version JDK whenever possible.

这篇关于JDK,JRE兼容JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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