Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #18698

Re: import order

Newsgroups comp.lang.java.programmer
Date 2012-09-12 14:30 -0700
References <c15a6122-257c-4e8a-bb11-9c7684d5d222@googlegroups.com> <k2qrs2$tg2$1@localhost.localdomain>
Message-ID <27de199c-6cf5-4795-9607-767971559344@googlegroups.com> (permalink)
Subject Re: import order
From Lew <lewbloch@gmail.com>

Show all headers | View raw


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/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).

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

import order bob smith <bob@coolfone.comze.com> - 2012-09-12 13:21 -0700
  Re: import order Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 16:27 -0400
  Re: import order Martin Gregorie <martin@address-in-sig.invalid> - 2012-09-12 20:38 +0000
    Re: import order Lew <lewbloch@gmail.com> - 2012-09-12 14:30 -0700
      Re: import order Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 17:37 -0400
        Re: import order Lew <lewbloch@gmail.com> - 2012-09-12 14:48 -0700
          Re: import order Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 17:55 -0400
            Re: import order Lew <lewbloch@gmail.com> - 2012-09-12 22:36 -0700
  Re: import order Robert Klemme <shortcutter@googlemail.com> - 2012-09-12 23:27 +0200
    Re: import order Lew <lewbloch@gmail.com> - 2012-09-12 14:31 -0700
      Re: import order Martin Gregorie <martin@address-in-sig.invalid> - 2012-09-12 21:53 +0000
        Re: import order Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:01 -0400
    Re: import order Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 17:35 -0400

csiph-web