在类层次结构中混合使用Java 1.4和1.6字节码 [英] Mixing Java 1.4 and 1.6 bytecode in a class hierarchy

查看:91
本文介绍了在类层次结构中混合使用Java 1.4和1.6字节码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题首先,故事将如下:

The question first, the story will follow:

在类层次结构中混合使用不同的字节码版本是否安全?有什么风险?

Is it safe to mix different bytecode version in a class hierarchy? What are the risks?

对于一个案例,C类扩展B,B类扩展A类.A类实现接口I.
我的问题包括以下示例场景:

For a case, Class C extends B, Class B extends Class A. Class A implements Interface I. My question would involve following example scenarios:


  • A类编译为Java 1.6字节码,并具有1.6特性,如泛型等。继承人,即B和C被编译为1.4字节码。

  • 接口我编译为1.6,而实现者编译为1.4。

  • 涉及不同版本的其他异乎寻常的继承场景字节码。

我尝试了很多我能想象的场景,似乎运行得很好。但是我仍然觉得这里要求的冲动,因为我只知道表面上的Java;我知道如何编写和调整Java,但不知道幕后发生了什么。

I have tried as many scenarios I could imagine and it seems to run just fine. However I still feel the urge to ask here as I only know Java at the surface; i know how to code and tweak Java but don't really know what happen under the hood.

现在对于那些无法自拔的人来说为什么会这样?你需要这样做吗???。

Now for those minds who can't help themselves to ask "why would you need to do that???".

我正在一个项目中评估通过RMI连接到EJB 2的遗留Java 1.4 Swing应用程序的迁移Java 1.6 Swing连接到运行在1.6之上的较新版本的App Server。 J2EE平台仍然是1.4(EJB 2)。

I'm in a project to assess the migration of legacy Java 1.4 Swing app, connected to EJB 2 via RMI, to Java 1.6 Swing connected to newer version of App Server running on top of 1.6 also. The J2EE platform will still be 1.4 (EJB 2).

迁移不会重新编译所有内容到1.6,但它将是代码并编译新功能到1.6\" 。
他们做事的方式是这样的:
他们在CVS中只有一条路径,每个人都在那里提交。没有任何标签/分支来获取生产代码。
每当需要添加新功能时,他们从生产服务器获取JAR,爆炸它们,根据需要替换或添加新类,重新打包罐子,将它们放回服务器。
因此,如果他们将使用Java 6编译并使用上述方法进行部署,那么将会有很多异常混合的1.4和1.6字节码。

The migration will not be "recompile everything to 1.6", but it will be "code and compile new features to 1.6". The way they do things is like this: They only have one path in the CVS, everyone commits there. No tags/branches whatsoever to get the production code. Whenever a new feature need to be added, they get the JARs from production server, explode them, replace or add new classes as needed, repackage the jars, put them back to server. Therefore, if they will use Java 6 to compile and using the above method for deployment, there will be a lot of exotic mixes of 1.4 and 1.6 bytecodes.

推荐答案

JVM字节代码在Java 1.0和Java 6之间没有显着差异。在Java 7中,它们添加了一条新指令。 Woohoo。

The JVM byte code is not siginificantly different between Java 1.0 and Java 6. In Java 7 they add one new instruction. Woohoo.

字节码的工作方式变化很小

There are so little changes in how the byte code works that


  • JVM不支持访问外部类私有成员的嵌套类,这可以通过生成的代码来实现。

  • JVM不支持对泛型的运行时检查,例如你不能 new T()其中T是通用的。

  • The JVM doesn't support nested classes accessing private members of outer classes, this works through generated code.
  • The JVM doesn't support runtime checks for generics e.g you cannot new T() where T is a generic.

基本上,它们使JVM更智能更快,但直到最近才不惜一切代价改变字节代码工作方式的模型。

Basically, they make the JVM smarter and faster but until recently changing the model of how the byte code works has been avoided at all costs.

这篇关于在类层次结构中混合使用Java 1.4和1.6字节码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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