difference between "import" with and without wildcard.

P

Peter Rilling

I am new to Java and am wondering what is the difference between using and
not using a wildcard in the "import" statement. Are there performance
issues with importing all classes versus just the ones that are used?
 
E

Elie De Brauwer

Peter said:
I am new to Java and am wondering what is the difference between using and
not using a wildcard in the "import" statement. Are there performance
issues with importing all classes versus just the ones that are used?

When you do import javax.swing.* you import *all* classes in the
javax.swing package. If you import javax.swing.JLabel you only
import the JLabel class.
Afaik, the import is only used at compile time, so only a performance
issue can exist at compile time (if you import a whole load of classes
it takes longer to check if the class you are using is part of that
collection). But at runtime this won't make any difference.
Most of the time it is clearer to import only the classes you plan to
use so somebody reading you code knows directly what classes will be used.

hth
Elie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top