什么是“编译器兼容级别”在Eclipse中? [英] What is "compiler compliance level" in Eclipse?

查看:88
本文介绍了什么是“编译器兼容级别”在Eclipse中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一段时间我试图理解,但是我仍然没有得到Eclipse中项目的编译器合规级别的意思。我查看了这个网站和Google,并找不到我能理解的答案。



我想让我的程序能够在JRE 6上运行。 / p>

我可以做:项目>首选项> Java构建路径>库,并将JRE库用于JRE 6。


$ b $为什么这不够?



我从来没有明白为什么我还需要将编译器合规性设置设置为JRE 6。



我想了解在项目中使用JRE 6之间的差异,并将项目的编译器合规性设置设置为JRE 6。



解决方案

编译器合规性设置告诉编译器假装它不同版本的Java。



Java 8编译器将生成Java 8版本的类文件格式的类文件,并接受Java 8源文件。 JRE 6无法加载此版本,因为它是在JRE 6之后创建的。



如果将合规级别设置为JRE 6,它将编译Java 6个源文件转换为Java 6类文件。



这就像将Word文档保存为Word 97-2003格式 - 以便Word 97-2003可以读取您的文档。您以Java 6格式保存类文件,以便Java 6可以读取它们。


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.

Let's say I want my program to be able to run on JRE 6.

I can do: Project > Preferences > Java Build Path > Libraries, and set the JRE library I use to JRE 6.

Why isn't this enough?

I never understood why I also need to set the compiler compliance setting to 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.

What exactly does compiler compliance level mean?

解决方案

The compiler compliance setting tells the compiler to pretend it's a different version of Java.

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.

If you set the compliance level to "JRE 6", it will instead compile Java 6 source files into Java 6 class files.

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屋!

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