import order

B

bob smith

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?
 
A

Arne Vajhøj

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
 
R

Robert Klemme

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
 
L

Lew

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/library/8etzzkb6(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).
 
A

Arne Vajhøj

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
 
L

Lew

Arne said:
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.
 
A

Arne Vajhøj

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
 
A

Arne Vajhøj

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
 
L

Lew

Arne said:
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).

Yes, you are right. I stand corrected.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top