What is effected by redundant java import statements?
Do they effect the compiled runtime (performance/size)?
or just stuff like intellisense?
To ask differently:
how important is it to remove them?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Import statements only affect what happens during compile time.
The compiler takes this code, and creates a
.classfile that represents your code in an executable format (something in binary).In the end, the binaries are exactly the same, but the method by which they are made are different.
Let’s look at a simple case:
vs
when used in:
When the compiler hits the word
List, in the first case, it will need to figure out ifListexists in that set of classes or not. In the second case, it is already given it explicitly, so its much easier.In essence, what happens is the compiler must take all the classes existing in the
importstatements and keep track of their names so that, if you use it, the compiler can then retrieve the appropriate functions that you are calling.Sometimes, there are classes that have the same name in multiple packages. It is in this case (which Thomas is referring to) that you should not use the
*to select all the classes in the directory.It is best practice to explicitly describe your class usage.