有没有办法在 Eclipse 中删除 Java 1.5 之前不推荐使用的警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3210117/
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-09-19 14:52:47  来源:igfitidea点击:

Is there a way, in Eclipse, to remove deprecated warnings, pre Java 1.5

javaeclipse

提问by P. Deters

We have an internal Java library, that for legacy reasons, needs to be compiled using Java 1.4. However, this lib has gone through several versions, the latter of which have had certain methods and objects deprecated. For client support reasons, the code needs to use some of these deprecated methods/objects. As such, we always keep the latest lib on the build path of our projects (in Eclipse).

我们有一个内部 Java 库,出于遗留原因,需要使用 Java 1.4 进行编译。然而,这个库已经经历了几个版本,后者已经弃用了某些方法和对象。出于客户端支持的原因,代码需要使用其中一些已弃用的方法/对象。因此,我们始终在项目的构建路径上(在 Eclipse 中)保留最新的库。

I would like to

我想要

@SuppressWarnings("deprecation");

Though, do to the aforementioned 1.4 dependency, this is not possible.

虽然,对上述 1.4 依赖做,这是不可能的。

Is there a way for me to remove the warnings, if only from my Eclipse Problems view, and somewhat cleanup my development environment?

有没有办法让我删除警告,如果只是从我的 Eclipse 问题视图中删除,并稍微清理我的开发环境?

回答by Pascal Thivent

Is there a way for me to remove the warnings, if only from my Eclipse Problems view, and somewhat cleanup my development environment?

有没有办法让我删除警告,如果只是从我的 Eclipse 问题视图中删除,并稍微清理我的开发环境?

You can configure the Java Compiler to ignore the Deprecated Warnings. I'd suggest to configure this setting for the specific project, not globally. To do so, right-clickon your project and go to Properties > Java Compiler > Errors/Warnings. Click Enable project specific settingsand then unfold Deprecated and restricted APIand select Ignorefor Deprecated API.

您可以将 Java 编译器配置为忽略已弃用的警告。我建议为特定项目而不是全局配置此设置。为此,右键单击您的项目并转到Properties > Java Compiler > Errors/Warnings。单击启用项目特定设置,然后展开已弃用和受限 API并为已弃用 API选择忽略

This will disable all deprecated warnings though.

不过,这将禁用所有已弃用的警告。

回答by Jon Skeet

If you're not concerned about deprecation anywherein that project, you could always give it custom project compilation settings and set it to ignore deprecation. It's not ideal, but it may well be better for you in this case than living with the deprecation warnings - it means you'll be able to spot ones in your otherprojects more easily.

如果您不关心该项目中任何地方的弃用,您始终可以为其提供自定义项目编译设置并将其设置为忽略弃用。这并不理想,但在这种情况下对您来说可能比忍受弃用警告更好 - 这意味着您将能够更轻松地在其他项目中发现警告。

回答by Peter Lawrey

You could treat it as a standalone project. If its legacy you won't need to update often. In your main project use the JAR created with a link to the source so you still see that. That way it won't be compiled so it won't create warnings all the time.

您可以将其视为一个独立的项目。如果它的遗产,您将不需要经常更新。在您的主项目中,使用带有源链接创建的 JAR,这样您仍然可以看到它。这样它就不会被编译,所以它不会一直创建警告。