dev@glassfish.java.net

Re: java.* - import first or last?

From: Bill Shannon <bill.shannon_at_oracle.com>
Date: Thu, 09 Dec 2010 01:16:26 -0800

Sahoo wrote on 12/08/2010 11:23 PM:
> On Thursday 09 December 2010 12:20 PM, Bill Shannon wrote:
>> Sahoo wrote on 12/08/2010 10:29 PM:
>>> One can't import p1.C and p2.C at the same time. If one imports p1.* and p2.C,
>>> then p2.C always wins irrespective of the order. So, what's the real issue?
>>
>> I often import java.util.* or java.io.* because really, don't you just want
>> to be able to use all of it whenever you want? (Ok, I know some people
>> believe religiously that you should never use "*" in an import; I don't want
>> to get into that here.)
>>
> Sorry, I still don't understand how the order matters in this case?

Maybe it's more style than correctness, but if there's any possible conflict
I want the java.* classes in preference to the com.sun.* classes.

> On a different note, I am not someone who is in that religious camp. I have
> actually configured my IDE to change to .* notation during code formatting if it
> figures out I have imported more than a certain number of classes from a
> package. I would be happier if I were allowed to import "java.*"
>
>>> I am one of those who import java.* at the end, because I like to see
>>> non-standard dependencies ahead of standard ones. I may not have done that
>>> consistently though.
>>
>> Did you also "#include <stdio.h>" last? :-)
> Yes and No. I hardly wrote any C code in my professional career, I spent quite a
> number of years writing C++ code and preferred including <stdio> to <stdio.h> ;-)
> I just checked the last real C++ code that I had written and there I have
> included standard header files after my own header files.

Well, at least you're consistent!

But, based on my experience, that is *extremely* unusual in C/C++ code.