Java eclipse magic: ... 语法错误,仅当源代码级别为 1.5 或更高时,可变参数才可用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1736730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:04:14  来源:igfitidea点击:

eclipse magic: ... Syntax error, varargs are only available if source level is 1.5 or greater

javaeclipse

提问by Omu

Yesterday I made a project in eclipse, and it was working, compiling. I used Eclipse Galileo for Java EE. Today I open eclipse and see lots of errors saying that stuff is not available and that it is only available if source level is 1.5.

昨天我在 eclipse 中做了一个项目,它正在工作,正在编译。我将 Eclipse Galileo 用于 Java EE。今天我打开 eclipse,看到很多错误,说东西不可用,只有在源级别为 1.5 时才可用。

What to do?

该怎么办?

采纳答案by Suraj Chandran

Check whether this works:

检查这是否有效:

  1. Go to your project's Properties
  2. On the Properties dialog choose the Java Compilernode in the left tree.
  3. Finally set the Compiler compliance levelto 1.5 or more.
  4. Rebuild the project.
  1. 转到您的项目 Properties
  2. 在“属性”对话框中,选择Java Compiler左侧树中的节点。
  3. 最后将 设置Compiler compliance level为 1.5 或更高。
  4. 重建项目。

回答by lwpro2

and something interesting for GWT. even though i am using java 6, it throw me error saying source level should be 5 or later.

和 GWT 有趣的东西。即使我使用的是 Java 6,它也会抛出错误,说源级别应该是 5 或更高版本。

Click the error, use the auto correct of eclipse, it change the compliance level to 5, solved the problem.

单击错误,使用eclipse的自动更正,将合规级别更改为5,解决了问题。

回答by Attila Csipak

See also: Eclipse: Syntax Error, parameterized types are only if source level is 1.5

另请参阅:Eclipse:语法错误,参数化类型仅当源级别为 1.5 时

(I know, I know, this question is older by a year, but the other one contains some additional info in Jeff's answer.)

(我知道,我知道,这个问题早了一年,但另一个问题在杰夫的回答中包含了一些额外的信息。)

回答by Timmy Chiu

Just make sure Java > Installed JREs has jre6 instead of jdk1.6.0

只要确保 Java > Installed JREs 有 jre6 而不是 jdk1.6.0

Eclipse seems detect jdk6 as not jre 1.5+

Eclipse 似乎将 jdk6 检测为不是 jre 1.5+

回答by Jyo the Whiff

Single answer couldn't solve my problem so I used both :

单一答案无法解决我的问题,所以我同时使用了两者:

  • First right click on the error in problems tab
  • click Quick fix
  • ok
  • right click on the project
  • build path
  • configure build path
  • remove JRE library
  • add JRE library
  • 首先右键单击问题选项卡中的错误
  • 单击快速修复
  • 好的
  • 右键单击项目
  • 构建路径
  • 配置构建路径
  • 删除 JRE 库
  • 添加 JRE 库

.... tada...done... :)

.... tada...完成... :)

回答by Tyler

If your JDK is already at or above 1.5 try changing your JDK compliance to something else, letting it build, and then back again.

如果您的 JDK 已经达到或高于 1.5,请尝试将您的 JDK 合规性更改为其他内容,让它构建,然后再返回。

  1. Open Preferences(Window -> Preferences)
  2. Navigate to Java -> Compiler
  3. Change the Compiler compliance levelto some other value
  4. Hit Applyand allow eclipse to rebuild
  5. Repeat steps 3 & 4 with desired Compiler compliance level
  1. 打开Preferences(窗口 -> 首选项)
  2. 导航 Java -> Compiler
  3. 将 更改Compiler compliance level为其他值
  4. 点击Apply并允许 eclipse 重建
  5. 重复第 3 步和第 4 步 Compiler compliance level

回答by Jave Newbie

  1. Open Window | Preferences.
  2. Java | Compiler.
  3. Change compiler compliance level to some other value.
  4. Hit apply, allowing eclipse to build.
  5. Change compiler compliance level to desired level of Java.
  1. 打开窗口 | 喜好。
  2. 爪哇| 编译器。
  3. 将编译器合规性级别更改为其他值。
  4. 点击应用,允许 eclipse 构建。
  5. 将编译器合规级别更改为所需的 Java 级别。

回答by Statham

Try this:

尝试这个:

Go to your project's Properties, set the Java Compiler compliance level to 1.6, let it rebuild the project, then switched back to 1.7 and rebuild it again.

转到您项目的属性,将 Java 编译器合规性级别设置为 1.6,让它重建项目,然后切换回 1.7 并再次重建它。

It worked for me :)

它对我有用:)

回答by CrossOverer

Perhaps your project lacks in some necessary jars. Try this:

也许您的项目缺少一些必要的 jar。尝试这个:

  • Right click your project>>build path>>select libraries>>add jars to add necessary jars in your project.
  • Go to your project's Properties, set the Java Compiler compliance level to 1.6 or above.
  • Go to your project's Properties,set the project facets. make the 'java' option to match your Java Compiler compliance level,such as '1.6'.
  • 右键单击您的项目>>构建路径>>选择库>>添加 jar 以在您的项目中添加必要的 jar。
  • 转到您项目的属性,将 Java 编译器合规性级别设置为 1.6 或更高。
  • 转到您项目的属性,设置项目方面。使“java”选项与您的 Java 编译器合规性级别相匹配,例如“1.6”。

回答by Ryan

I had the same issue. For me, my project's compiler settings were imported from my Workspace Configuration settings, which was set to 1.8...

我遇到过同样的问题。对我来说,我的项目的编译器设置是从我的工作区配置设置中导入的,该设置设置为 1.8 ...

I tried switching compiler levels and rebuilding, but no luck. What did the trick though, was the following:

我尝试切换编译器级别并重建,但没有运气。但是,诀窍是什么:

On your file system

在您的文件系统上

  1. Navigate to your project.

  2. Delete the .settingsfolder.

  3. Delete the .projectfile

  1. 导航到您的项目。

  2. 删除.settings文件夹。

  3. 删除.project文件

In Eclipse:

在日食中:

  1. Delete the project from your workspace - Ensure that you do not check the "Delete project contents on disk..." checkbox

  2. Import your project and allow it to build

  1. 从您的工作区中删除项目 -确保您没有选中“删除磁盘上的项目内容...”复选框

  2. 导入您的项目并允许它构建