在Eclipse中删除未使用的导入和保存操作变量 [英] Remove unused import and variable on save action in eclipse
问题描述
如何在Eclipse中的保存操作上删除未使用的导入和变量。
我有选项Ctrl + Shift + O。但只会删除未使用的导入。
我也想删除未使用的变量。
How can I remove unused import and variable on save action in eclipse. I have option Ctrl+Shift+O. but it remove only unused import. I want to remove unused variable also.
推荐答案
Eclipse只能使用 ctrl删除未使用的导入 + shift + O 。对于未使用的变量/功能,没有此类快捷方式(AFAIK)。默认情况下,Eclipse将针对此类变量显示警告消息,如果不显示,则可以从 windows>启用它。偏好> Java>编译器错误/警告>不必要的代码
Eclipse can remove only unused imports using ctrl+shift+O. For unused varibales/functions there is no such shortcut(AFAIK). Eclipse by default will show warning message for such type of variables, if it doesn't then you can enable it from windows > preferences > java > compiler > error/warnings > Unnecessary code
有一种删除未使用变量的方法:
There is one way to remove unused variables:
转到 windows>偏好> Java>代码样式>清理
编辑内置配置文件。
在不必要的代码标签中,选中删除未使用的私人成员
,然后按OK。
In the unnecessary code tab check remove unused private members
and press ok.
选择活动概要文件作为您刚刚创建的概要文件。
Select the active profile as the one you have just created.
现在要应用概要文件,在Java编辑器中打开上下文菜单,然后选择来源>清理
。
Now to apply profile, open the context menu in the Java Editor and select Source > Clean Up
.
这篇关于在Eclipse中删除未使用的导入和保存操作变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!