Any reason to clean up unused imports in Java, other than reducing clutter?

I don’t think that performance problems or something like that are likely if you are not removing the imports.

But there could be naming conflicts, in rare cases like importing the list interface.

In Eclipse you can always use a shortcut (depends on OS – Win: Ctrl + SHIFT + O and Mac: COMMAND + SHIFT + O) to organize the imports. Eclipse then cleans up the import section removes all the stale imports etc. If you are needing a imported thing again eclipse will add them automatically while you are completing the statement with Ctrl + SPACE. So there is no need in keeping unused code in you class.

As always unused code will distract you and other people while reading the code and leaving something in your active code because of maybe I need it later is mostly seen as bad practice.

Leave a Comment