Import operations only affect what happens at compile time.
The compiler takes this code and creates a .class file that represents your code in an executable format (something in binary form). A.
After all, binaries are exactly the same, but the method for creating them is different.
Let's look at a simple case:
import java.util.*;
against
import java.util.ArrayList; import java.util.List;
when used in:
//... List <String> someList = new ArrayList <String> (); //...
When the compiler falls into the word List , in the first case it needs to find out if List exists in this set of classes or not. In the second case, this has already been given explicitly; therefore, it is much simpler.
In essence, what happens, the compiler must take all the classes that exist in the import statements and keep track of their names so that if you use it, the compiler can then get the corresponding functions that you call.
Sometimes there are classes with the same name in multiple packages. It is in this case (which Thomas is talking about) that you should not use * to select all classes in the directory.
It is best to explicitly describe the use of your class.
source share