JDK 7类文件向后兼容JDK 6 [英] JDK 7 class file backward compatibility with JDK 6

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

问题描述

JDK 7的哪些功能(不包括invokedynamic,因为它不被java使用)导致新的类文件版本不符合JDK 6.它表明所有功能都可以由生成粘合代码的编译器实现。例如,可以使用编译器生成的重复ifeq语句来实现switch语句中的String。我希望能够为编译器提供-source 1.7 -target 1.6标志以符合jre 6,同时在jdk 7中使用项目硬币功能。

Which features of JDK 7 (excluding invokedynamic because it is not used by java) causing a new class file version which is not compliant with JDK 6. It seams that all features could be implemented by compiler generating glue codes. For example String in switch statement could be implemented using repeated ifeq statements generated by the compiler. I want to able to give -source 1.7 -target 1.6 flags to compiler to be compliant with jre 6 and at the same time use project coin features in jdk 7.

推荐答案

我还没有读过编译器的代码,但是一些新功能显然必须对字节码产生影响。

I haven't read the code for the compiler, but some of the new features must obviously have an impact on the bytecode.

简化的varargs方法调用实际上只是一个警告抑制,但它必须在字节码中留下一些标记,以便客户端代码可以以不同方式显示警告。

"Simplified varargs method invocation" is really just a warning suppression, but it must leave some marker in the bytecode so that client code can display warnings differently.

试用 -resources生成可以处理正常异常的代码以及在finally块期间抛出的第二个异常。使用新的 addSuppressed()方法。这并不是一个类文件格式的改变,但它显然不适用于早期的VM。

"Try-with-resources" generates code that can handle a normal exception plus a second exception thrown during the finally block. The extra exception is stored using the new addSuppressed() method. This isn't exactly a class-file format change, but it clearly wouldn't work on earlier VMs.

Multi-catch也产生的字节码略微不同于以前的编译器都可以生成现在,异常表中的多个条目将指向相同的catch主体。

"Multi-catch" also produces bytecode that's subtly different than any previous compiler could produce. Multiple entries in the exception table will now point to the same catch body.

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

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