JDK是“向上"吗?或“向后"兼容的? [英] Is JDK "upward" or "backward" compatible?

查看:220
本文介绍了JDK是“向上"吗?或“向后"兼容的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向后二进制兼容性(或向下兼容性)-使用旧版本库API构建的客户端可以在新版本上运行(

Backward binary compatibility (or downward compatibility) - an ability of clients built with an old version of library API to run on a new one (wiki).

向上二进制兼容性(或向前兼容性)-使用新版本的库API构建的客户端可以在旧版本上运行的功能(

Upward binary compatibility (or forward compatibility) - an ability of clients built with a new version of library API to run on old one (wiki).

Sun的有关JDK的一般文档自1.4.2版以来在J2SE 5.0中不兼容(以及 Java SE 6与J2SE 5.0的兼容性)描述JDK的兼容性如下:

The general Sun's document about JDK Incompatibilities in J2SE 5.0 since 1.4.2 (and Java SE 6 compatibility with J2SE 5.0 too) describes the compatibility of JDK as following:

JDK 5.0与Java 2 SDK v1.4.2 向上二进制兼容,但下面列出的不兼容之处除外.这意味着,除了指出的不兼容性之外,使用1.4.2版编译器构建的类文件将在JDK 5.0中正确运行..

JDK 5.0 is upwards binary-compatible with Java 2 SDK, v1.4.2 except for the incompatibilities listed below. This means that, except for the noted incompatibilities, class files built with version 1.4.2 compilers will run correctly in JDK 5.0.

我想文档写作者在这句话中强"兼容了强"和强"两个术语.他们描述了向后"兼容性,但称此功能为向上"兼容性.

I suppose that documentation writers have mixed up terms "upward" and "backward" compatibility in this sentence. They describe a "backward" compatibility, but call this feature as "upward" compatibility.

这是错字,错误还是预定用语? JDK是向上"还是向后"兼容?

Is this a typo, mistake or intended term here? Is JDK "upward" or "backward" compatible?

推荐答案

请注意,要使某些东西向后兼容,必须有一个对向兼容的对象(有意或无意).例如:DVD阅读器向后兼容CD还是CD向前兼容DVD阅读器?

Note that for something to be backwards compatible there must be a counterpart that is forwards compatible (either intentionally or unintentionally). For example: are the DVD readers backwards compatible with CD's or are the CD's forward compatible with DVD readers?

在这种情况下,取决于您查看的是编译器(或其生成的字节码)还是虚拟机.

In this case, it depends if you look at the compiler (or the bytecode it generates) or the virtual machine.

编译器不向后兼容,因为使用Java5 JDK生成的字节码将无法在Java 1.4 jvm中运行(除非使用-target 1.4标志进行编译).但是JVM是向后兼容的,因为它可以运行旧的字节码.

The compiler is not backwards compatible because bytecode generated with Java5 JDK won't run in Java 1.4 jvm (unless compiled with the -target 1.4 flag). But the JVM is backwards compatible, as it can run older bytecodes.

所以我想他们选择从javac的角度考虑兼容性(因为它是JDK特有的部分),这意味着生成的字节码可以在jvm的未来版本中运行(更相关)到JRE,但也捆绑在JDK中.)

So I guess they chose to consider the compatibility from the point of view of javac (as it is the part specific to the JDK), meaning that the bytecode generated can be run in future releases of the jvm (that is more related to the JRE, but also bundled in the JDK).

总而言之,我们可以说:

In brief, we can say:

  • JDK(通常)是向前兼容的.
  • JRE(通常)是向后兼容的.

(这也是很久以前应该学习的一课:编写编译器的人通常是正确的,而我们使用它们的人是错误的xD)

(And it also serves as a lesson that should be learnt long ago: the people writing the compilers are usually right, and we the people using them wrong xD)

顺便说一句,向后/向前和向下/向上配对而不是将它们混在一起更有意义吗?

By the way, doesn't it make more sense to pair backward/forward and downward/upward rather than mixing them up?

这篇关于JDK是“向上"吗?或“向后"兼容的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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