Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5028491

enum (wrongly) forces order of members, constructors

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P4
    • None
    • 5.0
    • tools
    • x86
    • windows_xp

    Description



      Name: rmT116609 Date: 04/07/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Error message from javac on trying to compile an enum where a constructor appears prior to enum constants.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile this code:
      enum egg {
                  egg(double w) {weight=w;} // constructor

                  // the enum constants
                  extraLarge(27.0),
                  large(24.0);

                  private double weight;

      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      expected clean compile with
          javac -source 1.5 -target 1.5 egg.java
      ACTUAL -
      Got error message:
      egg.java:3: '.class' expected
                  egg(double w) {weight=w;} // constructor
                             ^
      egg.java:6: ')' expected
                  large(24.0);
                             ^
      2 errors

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Move the constructor to AFTER the enum constants, then it compiles ok.

      (Incident Review ID: 245150)
      ======================================================================

      Attachments

        Activity

          People

            gafter Neal Gafter
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: