• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Java字节码和Java的不同版本兼容吗?

用户头像
it1352
帮助1

问题说明

如果我使用Java 5代码将应用程序编译为字节码,生成的.class文件是否可以在Java 1.4下运行?

If I compile an application using Java 5 code into bytecode, are the resulting .class files going to be able to run under Java 1.4?

如果后者可以工作并且我正在尝试在Java 1.4应用程序中使用Java 5框架,那么我应该注意什么吗?

If the latter can work and I'm trying to use a Java 5 framework in my Java 1.4 application, is there anything I should watch out for?

正确答案

#1

不! .class文件仅向前兼容. Java 5引入了新的类文件属性和格式更改,以处理Varargs,枚举和泛型. Java 4处理这些代码时只会失败.

Nope! .class files are forward compatible only. Java 5 introduced new classfile attributes and format changes, to handle Varargs, enums, and generics. Java 4 would just fail when processing these.

但是,javac上有不受支持的-target jsr14选项,它为某些Java 5语言功能生成了与JDK 1.4兼容的字节码.

However, there is the unsupported -target jsr14 option on javac that generates JDK 1.4-compatible bytecode for some Java 5 language features.

也有一些项目(例如 Retroweaver 使用Java 5语言功能在早期的JDK中

I found this good resource: Using Java 5 language features in earlier JDKs

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhccjbgg
系列文章
更多 icon
同类精品
更多 icon
继续加载