• Welcome to Valhalla Legends Archive.
 

imports

Started by po0f, December 25, 2004, 03:28 AM

Previous topic - Next topic

po0f

Is there any overhead incurred from importing all of the classes from a package? Example:
import java.somethingcool.*;
As opposed to just the class(es) you'll use:
import java.somethingcool.SomeClassA;
import java.somethingcool.SomeClassB;

MyndFyre

No; that information is only used at compile-time.

Generally I believe that programmers prefer to just import a single class as opposed to an entire package to avoid naming conflicts.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

IIRC, there is a compile-time overhead associated with importing *, since the compiler must go determine what classes you're summoning and bring in enough of them that it can satisfy any requests to them.  As Myndfyre said, there's no runtime overhead to it.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

iago

They're right, there's no runtime overhead, but there are coding style issues.

I personally import classes seperately.  Why? Take for example code that does:

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.net.*;

And then you see a call like this:
SocketInputStream s = new SocketInputStream(); 
(that doesn't really exist, but shh)
If you want to look up documentation, where do you go?

If the imports looked like:
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Color;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.File;
import java.net.Socket;
import java.net.INetAddress

Then you can look at the imports section and instantly see where it comes from.  If it's not listed in the imports, then you know it's coming from the same packet as the class you're looking at, and can check there.

This is less of a concern if you're using an IDE, but it's still nice (in my opinion) to be able to look up any class you see referenced in the file and know instantly where it came from.  * imports annoy me a lot.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*