eclipse 类型中的方法从未在本地使用非私有方法的警告

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

The method from the type is never used locally warning for non-private methods

eclipsesettingswarnings

提问by Maksim Dmitriev

I got this warning a lot of times for private methods. How to make Eclipse show the same (or similar) warning for public, default and protected methods?

对于私有方法,我多次收到此警告。如何让 Eclipse 为公共、默认和受保护的方法显示相同(或相似)的警告?

回答by Bananeweizen

Eclipse cannot do that, as public methods might be used from code that is not visible in the current workspace. But you could use the Unnecessary Code DetectorPlugin to find such methods.

Eclipse 不能这样做,因为公共方法可能会从当前工作区中不可见的代码中使用。但是您可以使用不必要的代码检测器插件来查找此类方法。

回答by JB Nizet

Doing it for private methods is easy because the scope to search for usage of the method is limited (only the class itself), and because the warning makes sense: since it's private, nobody from the outside can call the method, and since it's not called from inside the project, the method is probably useless, hence the warning.

为私有方法做这件事很容易,因为搜索方法使用的范围是有限的(只有类本身),并且因为警告是有道理的:因为它是私有的,外部没有人可以调用该方法,而且因为它不是从项目内部调用,该方法可能没用,因此发出警告。

Doing it for default methods could be done.

可以为默认方法执行此操作。

But doing it for public and protected methods would be counter-productive most of the time, because public and protected methods are part of the public interface of your classes, which could be used by other classes, out of the scope of the current eclipse project.

但是在大多数情况下为公共和受保护方法这样做会适得其反,因为公共和受保护方法是您的类的公共接口的一部分,可以被其他类使用,超出了当前 eclipse 项目的范围.

AFAIK, eclipse doesn't come with such a tool. But the UCDetectorplugin can find unused code in your project. Use with caution!

AFAIK,eclipse 没有附带这样的工具。但是UCDetector插件可以在您的项目中找到未使用的代码。谨慎使用!