简体   繁体   English

Eclipse 中的编译器合规性级别

[英]Compiler compliance level in Eclipse

I'm using JDK 1.8 version.我正在使用 JDK 1.8 版本。 And had imported some already written code.并导入了一些已经编写好的代码。 Got an error like below出现如下错误

The method actionPerformed(ActionEvent) of type new ActionListener(){} must override a superclass method

Googled, tured out that I need to set Compiler compliance level in Eclipse to 1.6 and problem solved.谷歌搜索,发现我需要将Compiler compliance level in Eclipse to 1.6设置Compiler compliance level in Eclipse to 1.6并解决问题。

Got 2 doubts有2个疑问

1) If I set 1.6, How my 1.8 jdk (Installed in my machine) is able to produce 1.6 versions of files and run it too ? 1)如果我设置了 1.6,我的 1.8 jdk(安装在我的机器上)如何能够生成 1.6 版本的文件并运行它? Is it possible 1.8 can produce 1.6 versions of java files and run it too ?是否有可能 1.8 可以生成 1.6 版本的 java 文件并运行它?

2) Is higher level of compliance level can handle lower verions, becasue its derived from lower to higher ? 2) 是否较高级别的合规性级别可以处理较低版本,因为它是从较低到较高的? If yes, then why its even required to change the compliance level, if it can be handled ?如果是,那么如果可以处理,为什么甚至需要更改合规性级别?

Does my doubts makes sense ?我的怀疑有意义吗?

tured out that I need to set Compiler compliance level in Eclipse to 1.6确定我需要将 Eclipse 中的编译器合规性级别设置为 1.6

No, you don't need to do that, and most likely it is a very bad idea .不,您不需要这样做,而且很可能这是一个非常糟糕的主意 Setting compiler compliance level to 1.6 instructs your modern Java compiler to pretend it is the old Java 6 compiler.将编译器合规性级别设置为 1.6 会指示您的现代 Java 编译器假装它是旧的 Java 6 编译器。 This means old code doesn't have to be modified to work with the new language version, but it also means you will be unable to use any language features that have been added to the Java language in the last 15 years .这意味着无需修改旧代码即可使用新语言版本,但也意味着您将无法使用在过去15 年内添加到 Java 语言中的任何语言功能。 That sounds like a very high price to pay to avoid having to slightly adjust old code to compile under a new Java version.为了避免在新的 Java 版本下编译旧代码而不得不稍微调整一下,这听起来是一个非常高的代价。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM