You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by N G <ni...@gmail.com> on 2005/10/09 14:29:25 UTC

[OT] Type of import statement

Does anyone know if it makes any kind of difference if you use "*" in your
import statements like:
import java.util.*;
 vs.
 import java.util.Collection;
 Is one better than the other? Does one take longer than the other when
compiling/executing?
 Thanks,
NG.

Re: [OT] Type of import statement

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
It makes no difference at runtime.  At compile-time a wildcard import 
can result in longer compile times, but it's one of those things where 
you would probably only notice in the aggregate.  The difference, most 
of the time I'd say, won't be enough to be of any real concern.

There is of course the debate about which leads to more readable code. 
This is generally a matter of taste.  I personally prefer always 
importing specific classes because I like being able to look in one 
place to see exactly what a class depends on.  Some people feel that 
using wildcards reduces the "noise" of a lot of import statements, which 
does make some sense.

One thing to consider in favor of specific imports is that with wildcard 
imports you can run into ambiguities.  If you have:

import foo.*;
import bar.*;

... and there happens to be a class Node in both packages, that you want 
to use, you have a problem.  Also, even if Node only exists in package 
foo initially, and then later someone adds a Node class to package bar, 
all of a sudden you'll find that your class doesn't compile and you'll 
have to track it down.  Kind of annoying if it's in production code that 
has been compiling properly for a year and all of a sudden it doesn't 
and the guy that originally wrote it is gone, now someone potentially 
less familiar with the code has to figure it out.

Frank

N G wrote:
> Does anyone know if it makes any kind of difference if you use "*" in your
> import statements like:
> import java.util.*;
>  vs.
>  import java.util.Collection;
>  Is one better than the other? Does one take longer than the other when
> compiling/executing?
>  Thanks,
> NG.
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org