在 Java 1.6 中弃用

发布于 2024-08-12 17:08:14 字数 204 浏览 4 评论 0原文

在 Java 1.5 中,要弃用某个方法,您可以:

@Deprecated int foo(int bar) {
}

在 Java 1.6 中编译该方法会产生以下结果:

语法错误,仅注释 如果源级别为 1.5,则可用

有什么想法吗?

In Java 1.5, to deprecate a method you would:

@Deprecated int foo(int bar) {
}

Compiling this in Java 1.6 results in the following:

Syntax error, annotations are only
available if source level is 1.5

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

网白 2024-08-19 17:08:14

您必须告诉编译器使用 1.6:

javac -source 1.6

或您的 IDE/构建系统的等效版本(正如其他人所建议的那样)。

You have to tell the compiler to use 1.6:

javac -source 1.6

Or equivalent for your IDE/build system (as others have suggested).

笨死的猪 2024-08-19 17:08:14

首先,它的 @Deprecated,其次 - 仔细检查您是否真的使用 Java 1.6 进行编译。你用什么? javac?蚀?

如果使用 javac,请确保您的 JAVA_HOME 设置为指向 JDK 6,而不是 JDK 1.4.2
如果使用 Eclipse(或任何 IDE),右键单击项目 >属性>并搜索编译器级别。

First, its @Deprecated, and second - double-check if you are really compiling with Java 1.6. What are you using? javac? Eclipse?

If using javac, make sure your JAVA_HOME is set to point to JDK 6, not JDK 1.4.2
If using Eclipse (or any IDE), right click the project > properties > and search for compiler level.

美人迟暮 2024-08-19 17:08:14

语法错误,注释仅在源级别为 1.5 时可用

这是典型的 IDE 错误消息。您已将工作区或项目配置为使用合规性级别 1.4 或更早版本。假设它是 Eclipse(至少可以识别为 Eclipse 错误),那么您需要转到 Java >工作区首选项中的编译器,并将编译器合规性级别设置为 1.5 或更高版本。您还需要在项目属性的 Java Compiler 条目中检查这一点。

Syntax error, annotations are only available if source level is 1.5

This is a typical IDE error message. You've configured the workspace or the project to use compliance level 1.4 or older. Assuming that it's Eclipse (it's at least recognizeable as an Eclipse error), then you need to go to Java > Compiler in workspace preferences and set the Compiler compliance level to 1.5 or newer. You need to check this in the Java Compiler entry in Project's properties as well.

旧瑾黎汐 2024-08-19 17:08:14

如果您使用的是 Eclipse IDE,则

1- 在 Project Explorer 中选择您的项目

2- 转到项目 ->属性-> Java 编译器

3- 选中“启用项目特定设置”选项

4- 将“编译器合规级别”设置为“1.6”

注意:如果已设置为 1.6,则将其更改为 1.5。

5- 按“应用”按钮。

IDE 存在问题,有时它不会选择默认选择的编译器合规性级别。因此,您必须切换它并按应用按钮才能使更改生效。

If you are using Eclipse IDE then

1- Select your project in Project Explorer

2- Go to Project -> Properties -> Java Compiler

3- Check the option for 'Enable project specific settings'

4- Set the 'Compiler compliance level' to '1.6'

NOTE: If already set to 1.6 then change it to 1.5.

5- Press the 'Apply' button.

There are issues with the IDE and at times it just doesn't pick up the default selected compiler compliance level. Therefore you have to toggle it and press the apply button for the changes to take effect.

后知后觉 2024-08-19 17:08:14

阅读了迄今为止的回复后,我发现对于 Eclipse 所涉及的情况存在一些混乱。

我遇到了相同的语法错误,检查了工作区 Java 合规性(窗口 > 首选项 > Java > 编译器),并惊讶地发现编译器合规性级别为 1.6。 但是,我注意到此首选项页面顶部的链接配置项目特定设置。该链接会将您带到项目自己的设置。

您也可以从主菜单导航到那里。在这种情况下项目>属性> Java 编译器。有一个标记为启用项目设置的复选框,在我的例子中,该复选框已选中且设置为 1.4,但我不记得明确设置过它。无论如何,您可以将合规性设置设置为工作台的默认设置,或者将项目设置更改为 1.5 或更高。

这应该可以修复语法错误。

Having read the responses to date, I can see that there is some confusion as to what is happening where Eclipse is involved.

I had the same syntax error, checked workspace Java compliance (Window > Preferences > Java > Compiler) and was surprised to see a complier compliance level of 1.6. However, I noticed the link Configure Project Specific Settings at the top of this preference page. The link takes you to the project's own settings.

You can navigate there from the main menu, too. In this case Project > Properties > Java Compiler. There is a check box labelled Enable Project Settings and in my case this was checked and the setting was 1.4, though I do not remember setting it explicitly. Anyway, you can either let the compliance setting to default to that of the workbench or change the project setting to 1.5 or higher.

This should fix the syntax error.

黎夕旧梦 2024-08-19 17:08:14

我怀疑您的源级别设置为低于 1.5。一般来说,在 Java 6 中应该没问题。

你编译得怎么样?如果使用 Eclipse,您的项目/工作区设置在编译器/JDK 合规性级别下有何说明?

如果您使用的是 javac,请运行

javac -version

以检查您真正使用的版本。

I suspect you've got your source level set to lower than 1.5. It should be fine in Java 6 in general.

How are you compiling? If it's with Eclipse, what do your project/workspace settings say under Compiler / JDK Compliance Level?

If you're using javac, run

javac -version

to check what version you're really using.

好久不见√ 2024-08-19 17:08:14

您确定使用 Java 1.6 而不是 1.4(或更早版本)进行编译吗?
你使用什么编译器?

Are you sure you are compiling with Java 1.6 not 1.4 (or older)?
What compiler are you using?

隔纱相望 2024-08-19 17:08:14

@Deprecated 不是 @Deprecate

如果您使用的是 Eclipse,请确保 Java 编译器的设置设置为 1.6 合规性。

@Deprecated not @Deprecate

If you are using Eclipse, make sure the settings for the Java Compiler are set to 1.6 compliance.

属性 2024-08-19 17:08:14

即使在eclipse中使用java 1.6也会出现这种情况。单击该项目,然后右键单击它。转到属性,在 Java 编译器部分首先检查启用项目特定,然后手动选择 1.6 版本,即使默认情况下它已经存在。这解决了我的问题。

This can occur even if java 1.6 is used in eclipse. Click the project and then right click it. Go to properties and in Java compiler section first check enable project specific then manually select 1.6 version even if it is already there by default. This fixed my problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文