什么是“编译器合规级别"?在 Eclipse 中? [英] What is "compiler compliance level" in Eclipse?
问题描述
有一段时间我试图理解,但我仍然不明白 Eclipse 中项目的编译器合规级别"到底是什么意思.我翻遍了这个网站和谷歌,找不到我能理解的答案.
For some time I tried to understand, but I still don't get exactly what "compiler compliance level" for a project in Eclipse means. I looked all over this site and Google and couldn't find an answer I could understand.
假设我希望我的程序能够在 JRE 6 上运行.
Let's say I want my program to be able to run on JRE 6.
我可以:项目>首选项>Java构建路径>库,并将我使用的JRE库设置为JRE 6.
I can do: Project > Preferences > Java Build Path > Libraries, and set the JRE library I use to JRE 6.
为什么这还不够?
我一直不明白为什么我还需要将编译器合规性设置设置为 JRE 6.
I never understood why I also need to set the compiler compliance setting to JRE 6.
我想了解在项目中使用 JRE 6 与将项目的编译器合规性设置设置为 JRE 6 之间的区别.
I'd like to understand the difference between using JRE 6 in a project, and setting the project's compiler compliance setting to JRE 6.
编译器合规级别究竟是什么意思?
推荐答案
编译器合规性设置告诉编译器假装它是不同版本的 Java.
The compiler compliance setting tells the compiler to pretend it's a different version of Java.
Java 8 编译器将生成 Java 8 版本的类文件格式的类文件,并接受 Java 8 源文件.JRE 6 无法加载此版本,因为它是在 JRE 6 之后创建的.
The Java 8 compiler will produce class files in the Java 8 version of the class file format, and accept Java 8 source files. JRE 6 can't load this version, because it was created after JRE 6 was.
如果您将合规性级别设置为JRE 6",它会将 Java 6 源文件编译为 Java 6 类文件.
If you set the compliance level to "JRE 6", it will instead compile Java 6 source files into Java 6 class files.
这就像将 Word 文档另存为Word 97-2003 格式"——这样 Word 97-2003 就可以阅读您的文档.您正在以 Java 6 格式保存类文件,以便 Java 6 可以读取它们.
It's like saving a Word document as "Word 97-2003 format" - so that Word 97-2003 can read your document. You're saving the class files in Java 6 format so that Java 6 can read them.
这篇关于什么是“编译器合规级别"?在 Eclipse 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!