Author | Message | Time |
---|---|---|
po0f | Is there any overhead incurred from importing all of the classes from a package? Example: [code]import java.somethingcool.*;[/code] As opposed to just the class(es) you'll use: [code]import java.somethingcool.SomeClassA; import java.somethingcool.SomeClassB;[/code] | December 25, 2004, 9:28 AM |
Myndfyr | 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. | December 25, 2004, 9:37 AM |
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. | December 25, 2004, 5:43 PM |
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. | December 26, 2004, 7:59 PM |