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

后端 未结 11 1363
生来不讨喜
生来不讨喜 2020-11-28 06:34

Is there any good reason to avoid unused import statements in Java? As I understand it, they are there for the compiler, so lots of unused imports won\'t have any impacts o

11条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 07:19

    FYI, This caught me out, as I didn't think organize imports actually removed unused imports, I thought it just sorted them.

    Automatically removing imports during a save operation caused me some grief when for example, during development or testing you have a problem and comment out some code, when you save it, the imports used by the commented out section of code are removed. Sometimes this is not a problem as you can undo (Ctrl+Z) the changes, but other times it is not so simple as you may have made other changes. I also had a problem where when I uncommented the code (I have previously commented out then saved, thus removing the imports for that code), it automatically tried to guess the imports that were needed and picked up the wrong ones (e.g I think I had a StringUtils class being used and it picked another one with the same name from the wrong library).

    I prefer to manually organize imports rather than have it as a save action.

提交回复
热议问题