Import package.* vs import package.SpecificType [duplicate]

Would it suppose any difference regarding overhead to write an import loading all the types within one package (import java.*); than just a specific type (i.e. import java.lang.ClassLoader)? Would the second one be a more advisable way to use than the other one?


Take a look at the java API, and you'll see many classes and interfaces with the same name in different packages.

For example:

java.lang.reflect.Array
java.sql.Array

So, if you import java.lang.reflect.* and java.sql.* you'll have a collision on the Array type, and have to fully qualify them in your code.

Importing specific classes instead will save you this hassle.


There is not a performance or overhead cost to doing import .* vs importing specific types. However, I consider it to be a best practice to never use import .* My primary reason for this is I just like to keep things straightward, clean and with as little ambiguity as possible, and I think with a .* import you lose that.