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

拥有回忆 提交于 2019-12-24 10:57:34

问题


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?


回答1:


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.

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




回答2:


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 Detector Plugin to find such methods.



来源:https://stackoverflow.com/questions/15631664/the-method-from-the-type-is-never-used-locally-warning-for-non-private-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!