1

In my java project, during the process of refactoring my code, I see a lot of redundant packages. Eclipse marks them in light yellow as shown in the image below

enter image description here

What is the suggested practice of handling hese ? Do these redundant packages have any performance impact and if yes, would be interested in knowing how.

HopeKing
  • 3,317
  • 7
  • 39
  • 62
  • 2
    It has 0 impact at runtime. Imports don't exist at runtime. They're just a convenience for you, the developer, to be able to use simple class names rather than fully qualified class names in the source code. The byte code doesn't use imports. – JB Nizet Apr 29 '17 at 11:39
  • Thanks - that makes it clear. – HopeKing Apr 29 '17 at 12:08

1 Answers1

2

In eclipse there's a handy shortcut Ctrl+Shift+o which will organize your imports and remove unused.

Unused imports have a trivial impact on the compiler. It's not a big deal however it's distracting and best practice is to remove them.

Also it's prefered to use imports like this

import java.util.Map;
import java.util.List;

over this

import java.util.*;

using star will import all packages from util which you don't need in most scenarios...

Keshan Nageswaran
  • 8,060
  • 3
  • 28
  • 45
Martin Čuka
  • 16,134
  • 4
  • 23
  • 49
  • thanks for that. My only problem with ctrl+shift+o is that it is not very smart when conflicting packages are present and there are situations where this can cause problems. I prefer to manually add. But i take your point that it can be useful in removing redundant packages. That is a good idea. – HopeKing Apr 29 '17 at 12:34