[4401] in java-interest

home help back first fref pref prev next nref lref last post

Re: import efficiency

daemon@ATHENA.MIT.EDU (Jeremy Fitzhardinge)
Fri Dec 22 00:37:24 1995

From: "Jeremy Fitzhardinge" <jeremy@suede.sw.oz.au>
Date: Fri, 22 Dec 1995 15:13:12 -0500
In-Reply-To: "Elliotte Rusty Harold" <elliotte@blackstar.com>
        "import efficiency" (Dec 21,  6:57pm)
To: elliotte@blackstar.com
Cc: java-interest@java.sun.com

On Dec 21,  6:57pm, Elliotte Rusty Harold wrote:
> Subject: import efficiency
> Is there anything to be gained by being very specific about the 
> classes you import?  i.e. will my code be any bigger or slower if I 
> import java.util.* when I just want java.util.Random?  or any other 
> similar combinartion?  In other words should I make the effort to 
> only import the classes I use or should I be a pig and import 
> everything, and not worry about counting classes?

It will affect compile time, but it won't affect the class file at
all.  The less you import, the faster the compile will be.  If you do
an import foo.*, it'll probably cause the compiler to rummage around
much more than necessary.  Or perhaps not - anywhay, it doesn't matter
that much in the short term.

In the long term you may want to be more careful.  If you do an import
foo.* and have a class in your current package called "mypackage.bar"
which you only refer to as "bar", and then someone adds a public class
"bar" to "foo" then your compiles will fail because "bar" on its own has
become ambigious.  If you actually explicitly need both "mypackage.bar"
and "foo.bar" then you have to change all your source.  On the other
hand, if you don't need "foo.bar" at all, then you can just import
the parts of foo you do need, and use "bar" with impunity.

	J
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post