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

The behavior of enum is different between Java and Groovy in switch statement.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.1-rc-1
    • 1.1-rc-2
    • None
    • None
    • Windows 2000
      Groovy Version: 1.1-rc-1
      JVM: 1.6.0_02-b05

    Description

      The following code snippet can not be run, but after I used the full name such as Fruit.APPLE, Fruit.ORANGE, Fruit.BANANA, the code can be run successfully.

      public enum Fruit {
      	APPLE, ORANGE, BANANA
      }
      
      Fruit f = Fruit.BANANA
      println f
      switch (f) {
      	case APPLE:
      	  println "Apple"
      	  break
      	case ORANGE:
      	  println "Orange"
      	  break
      	case BANANA:
      	  println "Banana"
      	  break
      	default:
      	  println "Will not reach!"
      	  break  
      }
      

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            tiger_shark Tiger Shark
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: