What are the effects of redundant import statements in Java?

What is a redundant Java import statement?

Do they affect the compiled runtime (performance / size)? Or something like IntelliSense?

Make different demands: how important is it to delete them?

Solution

The import statement affects only what happens during compilation

The compiler accepts this code and creates one Class file, which represents your code (binary code) in executable format

Finally, binary files are identical, but they are made in different ways

Let's look at a simple case:

import java.util.*;

VS

import java.util.ArrayList;
import java.util.List;

be used for:

//...
List <String> someList = new ArrayList <String> ();
//...

When the compiler hits the word list, in the first case, it needs to find out whether the list exists in that group of classes In the second case, it has been explicitly given, so it is easier

Essentially, what happens is that the compiler must get all the classes that exist in the import statement and track their names so that when it is used, the compiler can retrieve the corresponding function you are calling

Sometimes, some classes have the same name in multiple packages In this case, you should not use * to select all classes in the directory

The best practice is to clearly describe your class usage

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>