Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > import order

Reply
Thread Tools

import order

 
 
bob smith
Guest
Posts: n/a
 
      09-12-2012
Does order ever matter with import statements in Java?

I don't think so.

I noticed it does sometimes matter with C++. Why the difference?
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-12-2012
On 9/12/2012 4:21 PM, bob smith wrote:
> Does order ever matter with import statements in Java?
>
> I don't think so.


Correct.

If there is a conflict you get an error.

> I noticed it does sometimes matter with C++. Why the difference?


Weird. I thought C++ also gave errors in case of a conflict.

Arne


 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      09-12-2012
On 12.09.2012 22:21, bob smith wrote:
> Does order ever matter with import statements in Java?
>
> I don't think so.
>
> I noticed it does sometimes matter with C++. Why the difference?


C++ does not have import statements - as simple as that.

If you are referring to #include then we are talking about two
dramatically different mechanisms (don't let yourself be fooled of the
fact that both mechanisms are used to achieve similar goals).

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      09-12-2012
Martin Gregorie wrote:
> bob smith wrote:
>> Does order ever matter with import statements in Java?
>> I don't think so.
>> I noticed it does sometimes matter with C++. Why the difference?


C++ import directives (not statements!) are not the same as Java import directives.

C++ import directives pull in type libraries. Java import directives identify textual
aliases for fully-qualified class names.

> C/C++ #include statements can, and often do, contain further nested
> #includes, so its quite possible that not all of these will be inside the
> #ifndef ... #endif brackets that should check for and skip multiple
> inclusions.


He asked about import "statements". He didn't mention '#include'.

C++ has an import directive:
http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

That said, if the OP did mean '#include' your comments are on the mark.

> Since, unlike a C/C++ #include statement, an import doesn't pull in any
> source code, Java can never have this sort of clash.


Java 'import' and C++ '#include' are not the same thing at all. What Martin
tells you here is the difference.

Does source code order matter? Of course it does, and that's why '#include'
order matters, and Java 'import' order doesn't.

Whether you say it first, fourth or seventeenth, if you import 'List' as an alias
for 'java.util.List', it will alias that FQN (fully-qualified name).

--
Lew
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      09-12-2012
Robert Klemme wrote:
> bob smith wrote:
>> Does order ever matter with import statements in Java?

>
>> I don't think so.
>> I noticed it does sometimes matter with C++. Why the difference?


> C++ does not have import statements - as simple as that.


But it does have an '#import' directive, at least in the MS world.
http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

> If you are referring to #include then we are talking about two
> dramatically different mechanisms (don't let yourself be fooled of the
> fact that both mechanisms are used to achieve similar goals).


--
Lew
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-12-2012
On 9/12/2012 5:27 PM, Robert Klemme wrote:
> On 12.09.2012 22:21, bob smith wrote:
>> Does order ever matter with import statements in Java?
>>
>> I don't think so.
>>
>> I noticed it does sometimes matter with C++. Why the difference?

>
> C++ does not have import statements - as simple as that.
>
> If you are referring to #include then we are talking about two
> dramatically different mechanisms (don't let yourself be fooled of the
> fact that both mechanisms are used to achieve similar goals).


I assumed that he was talking about C++ using, which is doing
the same as Java import.

Arne


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-12-2012
On 9/12/2012 5:30 PM, Lew wrote:
> Martin Gregorie wrote:
>> bob smith wrote:
>>> Does order ever matter with import statements in Java?
>>> I don't think so.
>>> I noticed it does sometimes matter with C++. Why the difference?

>
> C++ import directives (not statements!) are not the same as Java import directives.
>
> C++ import directives pull in type libraries. Java import directives identify textual
> aliases for fully-qualified class names.
>
>> C/C++ #include statements can, and often do, contain further nested
>> #includes, so its quite possible that not all of these will be inside the
>> #ifndef ... #endif brackets that should check for and skip multiple
>> inclusions.

>
> He asked about import "statements". He didn't mention '#include'.
>
> C++ has an import directive:
> http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx


C++ does not.

MS C++ has.

Arne

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      09-12-2012
Arne Vajh°j wrote:
> Lew wrote:
>> C++ has an import directive:
>> http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

>
> C++ does not.
>
> MS C++ has.


Potayto, potahto.

At least one flavor of C++ has it, so C++ has it, somewhere, albeit as you point out,
not portably.

But then C++ isn't that portable anyway.

Perhaps the OP can tell us which of '#import', '#include' and 'using' he actually meant.

The answer remains much the same regardless - C++ is not Java. Java's 'import' is
not the same as any of those three C++ (-related) concepts.

--
Lew
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-12-2012
On 9/12/2012 5:48 PM, Lew wrote:
> Arne Vajh°j wrote:
>> Lew wrote:
>>> C++ has an import directive:
>>> http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

>>
>> C++ does not.
>>
>> MS C++ has.

>
> Potayto, potahto.
>
> At least one flavor of C++ has it, so C++ has it, somewhere, albeit as you point out,
> not portably.


Not in the C++ specification (ISO).

> Perhaps the OP can tell us which of '#import', '#include' and 'using' he actually meant.
>
> The answer remains much the same regardless - C++ is not Java. Java's 'import' is
> not the same as any of those three C++ (-related) concepts.


The difference between Java import and C++ using are slim. The only
difference I can think of is syntax (statement itself and where it is
legal).

Arne


 
Reply With Quote
 
Arne Vajh├Şj
Guest
Posts: n/a
 
      09-12-2012
On 9/12/2012 5:53 PM, Martin Gregorie wrote:
> On Wed, 12 Sep 2012 14:31:59 -0700, Lew wrote:
>
>> Robert Klemme wrote:
>>> bob smith wrote:
>>>> Does order ever matter with import statements in Java?
>>>
>>>> I don't think so.
>>>> I noticed it does sometimes matter with C++. Why the difference?

>>
>>> C++ does not have import statements - as simple as that.

>>
>> But it does have an '#import' directive, at least in the MS world.
>> http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx
>>

> Thanks for the link: I've never used MS C/C++ compilers, so #import was
> news to me.
>
> That said, it appears that #import pulls in and/or generates some sort of
> proprietary type definition file plus an #include file. So, it would
> appear that #import would suffer from exactly the same ordering problems
> as #include does.


It imports a COM type library.

But yes - it is also order specific.

Arne



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
import order or cross import Roland Hedberg Python 5 01-03-2007 11:25 PM
If you get an order # does it mean the order is accepted? =?Utf-8?B?U3RldmUxMDc3?= Windows 64bit 3 05-12-2005 11:46 PM
Traversion order cf. output order in XSL Soren Kuula XML 2 02-01-2004 09:10 AM
In which order are files looked for when loaded/requierd - and what'sthe order of suffixes? Stephan Kńmper Ruby 2 01-18-2004 02:07 PM
How to Display DropDownList with preserved order (custom order) cspoh ASP .Net Web Controls 0 07-31-2003 09:19 AM



Advertisments