Import question [message #147438] |
Fri, 05 March 2004 07:41  |
Eclipse User |
|
|
|
Originally posted by: pmdanger.yahoo.com
Hi,
Reading a book about java, i saw that we can use :
import javax.*
or
import javax.swing
import javax.xxxx
import javax.yyyy
which solution offer the best result in term of compilation ?
when is compilation fast ?
when is file size smaller ?
thanks in advance,
Maileen
|
|
|
|
Re: Import question [message #147478 is a reply to message #147470] |
Fri, 05 March 2004 09:58  |
Eclipse User |
|
|
|
Originally posted by: eclipse-user.jibeinc.com
Peter Manahan wrote:
> You probably get more responses to those kinds of questions on a java
> newsgroup like comp.lang.java.* newsgroups.
True. But I'll answer it because it's easy and important for Java
newbies to know about.
> Maileen wrote:
>
>> Hi,
>>
>> Reading a book about java, i saw that we can use :
>>
>> import javax.*
>>
>> or
>>
>> import javax.swing
>> import javax.xxxx
>> import javax.yyyy
>>
>> which solution offer the best result in term of compilation ?
>> when is compilation fast ?
>> when is file size smaller ?
First: in terms of compile speed and generated file size, there is
absolutely no difference between the two import formats. The import
statements are just syntactic sugar to make the code writer's life a
little easier - they do not end up in the compiled classes at all.
Second: always use the long form, unless you are importing a very large
number of classes from one package. The wildcard form is tempting,
especially for those programmers who are used to languages that
encourage as little typing as possible. But all those wildcard imports
make it difficult to determine where individual classes are coming from.
If I see a class that I'm not familiar with, such as FooBarAdapter, and
the code has a bunch of wildcard imports, it becomes very much a PITA to
determine what package FooBarAdapter comes from (yes, Eclipse helps in
that regard, but the point is still valid).
Eclipse automatically generates appropriate import statements for you
anyway, so you should never have to worry too much about this. There are
settings to tell it at what threshold to use the wildcard import for a
package - see Preferences > Java > Organize Imports (I have my threshold
set to 10, and I can't find any of my code that uses wildcard imports).
HTH,
Eric
--
Eric Rizzo
Software Architect
Jibe, Inc.
http://www.jibeinc.com
|
|
|
Powered by
FUDForum. Page generated in 1.03128 seconds