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
Here is how you can do it:
In Eclipse Go to Window -> Preferences-> Java -> Editor -> Save Actions and click on Perform the selected actions on save: Organize imports.
Enjoy!
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:
Go to windows > preferences > Java > code style > cleanup
Edit the built in profile.
In the unnecessary code tab check remove unused private members
and press ok.
Select the active profile as the one you have just created.
Now to apply profile, open the context menu in the Java Editor and select Source > Clean Up
.