facebook

JDK Compiler Compliance Question

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #251843 Reply

    Curt King
    Participant

    I need to maintain a project that will run under JDK 1.3. In the project-specific settings, I set “Compiler Compliance Level” to “1.3”.

    In one of my classes, I used the following statement:

    BigDecimal bd = new BigDecimal(0);
    

    which is valid in 1.5, but not in 1.3 (you can’t pass an int to the BigDecimal constructor).

    Should MyEclipse have caught this error? Is there something that I needed to do differently in order to have the error flagged?

    Thanks,
    Curt

    #251875

    Riyad Kalla
    Member

    Curt,
    There is a confusion of two things here and it’s caused by the fact that Eclipse ships it’s own internal Java compiler. What you did when you changed your setting was actually change the bytecode that the compiler generates, BUT you left the JDK 1.5 class files in your build path. You need to navigate to your project properties and go to your Java Build Path > Libraries tab and remove the 1.5 libraries and add your 1.3 libraries. Then your project will rebuild and catch the compilation error.

    #251916

    Curt King
    Participant

    I have downloaded and installed JRE 1.3 — I have removed the JDK 1.5 libraries from the project in question. I have cleaned and rebuilt the project.

    Unfortunately, it’s still not flagging the error. When I invoke code completion, I only see the valid 1.3 constructors for BigDecimal — but when I enter an integer as the argument, which is not valid in 1.3, the IDE does not flag it as a problem.

    Is there something else I’m missing?

    What I downloaded was the JRE, which does not have a version of javac. Does the compiler in Eclipse know to compile the project back to 1.3? If not, how do I tell it to use a different compiler?

    Thanks,
    Curt

    #251924

    Riyad Kalla
    Member

    Hmm, Curt you did the right steps. As long as the rt.jar file in your project is the 1.3 ones, that should be marked as an error. Double check your compiler settings for the project, they are still marked as 1.3 right?

    #251938

    Curt King
    Participant

    I’ve checked “Enable project specific settings”, because my Preferences tab for the IDE is still at 1.5. In the drop-down labelled “Compiler Compliance Level”, I’ve selected 1.3.

    On the Build Path dialog, I double-clicked “JRE System Library [JRE 1.5]” and replaced it with “JRE System Library [JRE 1.3]” (after setting it up in the “Installed JREs” section.)

    #251940

    Riyad Kalla
    Member

    I think the solution is even easier than we thought… you are probably using the wrong version of 1.3, I just downloaded the most recent version of 1.3.1 from Sun, and BidDecimal does accept a constructor with an arg:
    http://java.sun.com/j2se/1.3/docs/api/java/math/BigDecimal.html

    #251944

    Curt King
    Participant

    It accepts a constructor with a double or a String, but not an int.

    So this line should work in 1.3:

    BigDecimal bd = new BigDecimal(0D);

    But this line should not:

    BigDecimal bd = new BigDecimal(0);

    Or at least it didn’t on my app server.

    It is entirely possible that this is just a Websphere quirk. But when I ran the BigDecimal(int) statement, I received a NoSuchMethodError because Websphere couldn’t compile the method.

    Curt

    #251945

    Riyad Kalla
    Member

    It’s most likely a WS quirk, you can always pass in a lower value cast for a higher value. FOr example you can pass an int as a double, no problem. What you cannot do and will be marked as a compiler error (without an explicit cast) is to down convert, because precision is list.

    WebSphere uses it’s own JDK, so it’s possible their compiler doesn’t like that OR that constructor was added later in the 1.3.1 revision and the version that ships with your copy of WS is an early 1.3 release that didn’t include those constructors.

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: JDK Compiler Compliance Question

You must be logged in to post in the forum log in