Disadvantages and disadvantages of imports and imports

I noticed that people prefer to import javax.swing.JFrame instead of javax.swing.* , Importing java.math.BigInteger instead of java.math.* Etc ... Is there a drawback in importing the whole package instead of importing directly or Is there any problem to import specifically?

+6
source share
4 answers

Importing a single class is usually preferred because they make it easy to understand which class is imported. And with a modern IDE it's very easy. Therefore, it is often considered a good style. There is no difference between importing packages and one class.

+2
source

Well, one point that I read regarding importing packages is that they cause problems if classes are added to the package later, causing ambiguity. Like jdk 1.1, containing only one List class in the java.awt package, jdk1.2 introduced another List class in the java.util package.

+3
source

Nothing. The import statement is a compiler directive and does not affect compiled code. You can read further here and here (you can probably find the best sources, but that was a 1 minute Google exercise).


This also seems like a duplicate of this question .

+1
source

You may notice slower compilation times when you import wildcards, because all classes will be loaded by the compiler at compile time. But this does not affect execution performance.

0
source

Source: https://habr.com/ru/post/890983/


All Articles