import order

Discussion in 'Java' started by bob smith, Sep 12, 2012.

  1. bob smith

    bob smith Guest

    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?
    bob smith, Sep 12, 2012
    #1
    1. Advertising

  2. bob smith

    Arne Vajhøj Guest

    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
    Arne Vajhøj, Sep 12, 2012
    #2
    1. Advertising

  3. 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/
    Robert Klemme, Sep 12, 2012
    #3
  4. bob smith

    Lew Guest

    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
    Lew, Sep 12, 2012
    #4
  5. bob smith

    Lew Guest

    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/library/8etzzkb6(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
    Lew, Sep 12, 2012
    #5
  6. bob smith

    Arne Vajhøj Guest

    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
    Arne Vajhøj, Sep 12, 2012
    #6
  7. bob smith

    Arne Vajhøj Guest

    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/library/8etzzkb6(v=vs.71).aspx


    C++ does not.

    MS C++ has.

    Arne
    Arne Vajhøj, Sep 12, 2012
    #7
  8. bob smith

    Lew Guest

    Arne Vajhøj wrote:
    > Lew wrote:
    >> C++ has an import directive:
    >> http://msdn.microsoft.com/en-us/library/8etzzkb6(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
    Lew, Sep 12, 2012
    #8
  9. bob smith

    Arne Vajhøj Guest

    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/library/8etzzkb6(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
    Arne Vajhøj, Sep 12, 2012
    #9
  10. 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/library/8etzzkb6(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
    Arne Vajhøj, Sep 12, 2012
    #10
  11. bob smith

    Lew Guest

    Arne Vajhøj wrote:
    > 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.

    --
    Lew
    Lew, Sep 13, 2012
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Soren Kuula
    Replies:
    2
    Views:
    481
    Soren Kuula
    Feb 1, 2004
  2. Joerg Sonnenberger

    Nested packages and import order bug

    Joerg Sonnenberger, Oct 6, 2003, in forum: Python
    Replies:
    0
    Views:
    298
    Joerg Sonnenberger
    Oct 6, 2003
  3. Roland Hedberg

    import order or cross import

    Roland Hedberg, Jan 3, 2007, in forum: Python
    Replies:
    5
    Views:
    344
    Gabriel Genellina
    Jan 3, 2007
  4. cspoh
    Replies:
    0
    Views:
    233
    cspoh
    Jul 31, 2003
  5. Stephan Kämper
    Replies:
    2
    Views:
    227
    Stephan Kämper
    Jan 18, 2004
Loading...

Share This Page