Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3985

error in instance initializer for Enum element, without special method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.0
    • 1.7.1, 1.8-beta-1
    • None
    • None
    • Mac OS X

    Description

      enum Color {
          RED {
            { println("foo"); } // Instance initalizer
          },GREEN,BLUE
      }
      

      makes an error like:

      $ groovy  enumtest.groovy
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /Users/uehaj/src/groovy/enumtest.groovy: -1: You are not allowed to overwrite the final method $INIT([Ljava.lang.Object;) from class 'Color'.
       @ line -1, column -1.
      1 error
      

      following is OK.

      num Color {
          RED {
            String toString() {}
            { println("foo"); } // Instance initalizer
          },GREEN,BLUE
      }
      

      Attachments

        1. enumtest.groovy
          0.2 kB
          UEHARA Junji

        Activity

          People

            roshandawrani Roshan Dawrani
            uehaj UEHARA Junji
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: