Eclipse - "Comparing Identical Expressions" 警告

Eclipse - "Comparing Identical Expressions" Warning

我正在使用 Eclipse 的“4.7.2 2017 年 12 月更新”版本,当我使用时收到警告:

System.out.println(20 % 10 == 0);

并且在 "Problems" 选项卡中显示:Warnings (1 item) > Comparing Identical Expressions

那么我该如何解决这个警告,我必须在 项目属性 > Java 编译器 > Errors/WarningsWorkspace Properties > Java > Compiler > Errors/Warnings 或在 Project Properties > Project Preference?

里面

Eclipse 告诉您这个表达式将永远为真。

如果您真的想关闭它,您可以在 'Java > Compiler > Errors/Warnings' 的首选项中为此设置行为。在 'Potential programming issues' 部分中,将 'Comparing identical values' 的操作设置为 'Ignore'

对于单个项目,这可以在 'Java Compiler > Errors/Warnings' 中的项目属性中进行配置。

您也可以使用@SuppressWarnings("all"),但它当然会关闭该代码块上的所有警告