Eclipse missing wrong return type

Discussion in 'Java' started by mike, Aug 18, 2010.

  1. mike

    mike Guest

    Hi,

    We have the following method.

    private int getOurId(Object value, Transaction c)
    throws Exception {
    if (value == null) {
    return -1;
    }
    return ((MyInterface) value).getMyId(c);
    }

    And getMyId(c) returns an Integer object. We were expecting Eclipse to
    give a compilation error, since return type is int for method, and
    show the error in red within IDE. When running ant we get a
    compilation error. We fixed with intValue().
    The only difference we have is that we use 1.4 for ant and 1.5 in
    Eclipse. Could that give such a difference?

    //mike
    mike, Aug 18, 2010
    #1
    1. Advertising

  2. > The only difference we have is that we use 1.4 for ant and 1.5 in
    > Eclipse. Could that give such a difference?


    Yes, this feature is called autoboxing and new in Java 5. See
    <http://download-llnw.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html>

    It lets you switch between primitives and their wrapper classes.

    HTH,
    Daniel
    Daniel Schwering, Aug 18, 2010
    #2
    1. Advertising

  3. mike

    Lew Guest

    Attribute citations.

    [mike wrote:]
    >> The only difference we have is that we use 1.4 for ant and 1.5 in
    >> Eclipse. Could that give such a difference?


    Daniel Schwering wrote:
    > Yes, this feature is called autoboxing and new in Java 5. See
    > <http://download-llnw.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html>
    >
    >
    > It lets you switch between primitives and their wrapper classes.


    Given that Java 5, never mind 1.4, is already officially obsolete and nearly
    six years old, it behooves us to be aware by now that version 5 brought in
    significant changes, and what they are.
    <http://en.wikipedia.org/wiki/Java_version_history#J2SE_5.0_.28September_30.2C_2004.29>

    Any time you're dealing with different language versions, be it Java, C, BASIC
    or what-have-you, it behooves you to be aware of the differences.

    One of the most significant differences between Java 5 and earlier versions,
    quite aside from generics and annotations and autoboxing and the rest, is the
    repair to the formerly broken "memory model", that is, the rules for how data
    are shared between concurrent threads.

    Even though Java 6 (the current, non-obsolete version that came out
    three-and-a-half years ago) introduced no significant new syntax, you still
    have to remain aware of differences between it and Java 5 if you're mixing
    those versions.

    You can use Java 5 to build Java 1.4 projects; you just have to be sure to use
    the -source, -target and -bootclasspath options correctly.

    Out of curiosity, why are you stuck with such obsolete Java versions? "The
    customer insists" is too shallow - what is the reasoning?

    --
    Lew
    Lew, Aug 18, 2010
    #3
  4. "Daniel Schwering" <> wrote in message
    news:...
    >> The only difference we have is that we use 1.4 for ant and 1.5 in
    >> Eclipse. Could that give such a difference?

    >
    > Yes, this feature is called autoboxing and new in Java 5. See
    > <http://download-llnw.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html>
    >
    > It lets you switch between primitives and their wrapper classes.



    Inn other words, the code you showed is a legal Java 1.5 program but not a
    legal Java 1.4 program. Using a newer Java version for development than for
    automated builds is a terrible idea, and you've just seen why.
    Mike Schilling, Aug 19, 2010
    #4
    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. DaKoadMunky
    Replies:
    8
    Views:
    3,306
    Leor Zolman
    May 14, 2004
  2. Gary Herron
    Replies:
    2
    Views:
    662
    Bruno Desthuilliers
    Jul 4, 2006
  3. Greenhorn
    Replies:
    15
    Views:
    809
    Keith Thompson
    Mar 6, 2005
  4. gk245
    Replies:
    2
    Views:
    1,197
    Christopher Benson-Manica
    May 6, 2006
  5. andrew cooke
    Replies:
    1
    Views:
    180
    Steven D'Aprano
    Apr 3, 2011
Loading...

Share This Page