You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2011/09/13 03:40:34 UTC

Re: [OT] Do imports inherit?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Doug,

On 9/11/2011 12:24 PM, Donald Jolley wrote:
> Thanks for the clarification.
> 
>> Also note that it's generally frowned upon to import with
>> wildcards; be
> specific with the classes you use.
> 
> Your suggestion certainly seems reasonable to me.  I do, however,
> note that the use of wildcards seems to be fairly prolific.  In
> this particular case my use of the wildcards was simply a case of
> my following a textbook example.

Wildcards are often used for brevity in examples, etc. because it's
important for the reader to know what the imports are, but there's no
reason to print 50 import statements.

As for practical matters, the compiler runs a bit faster when it only
"imports" a few classes instead of a whole package. Also, wildcard
imports can often lead to conflicts: for instance, both packages
javax.xml.stream.events and org.w3c.dom have a class called
"Comment"), so if you wildcard-import them, both, you'll have to
fully-qualify the use of "Comment" in the source code.

Also, since the Java API isn't static and new classes are added with
each release, you might find that "import java.io.*" in version 1.2 of
the API works just fine, but that when you upgrade to version 1.7, you
find that there is a new class that conflicts with one where there was
no historical conflict and suddenly your code no longer compiles
without changes. What looks like a bug in your code is actually just
laziness of the programmer that came back to bite you later in the
code's life.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5utJIACgkQ9CaO5/Lv0PDn4QCgqUoWn702LxDrMOiSKYRBp+/Q
PBUAn06IkpcRMZPDcdtlrFY9nTbI+ZHo
=EQMu
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org