Issue Details (XML | Word | Printable)

Key: GROOVY-2210
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Tiger Shark
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

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

Created: 15/Oct/07 04:02 AM   Updated: 02/Nov/07 08:39 AM
Component/s: None
Affects Version/s: 1.1-rc-1
Fix Version/s: 1.1-rc-2

Time Tracking:
Not Specified

Environment: Windows 2000
Groovy Version: 1.1-rc-1
JVM: 1.6.0_02-b05


 Description  « Hide
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  
}


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King added a comment - 16/Oct/07 08:28 AM
Indeed. Not only does Java allow the class name to be dropped, it requires it:
Temp.java:22: an enum switch case label must be the unqualified name of an enumeration constant
    case Fruit.ORANGE:
              ^

Jochen Theodorou added a comment - 02/Nov/07 08:39 AM
for now we require the class name in Groovy, because enums are not imported by default. It would differ to much from java. You can have the switch-case you showed if you add a static import like "import static Fruit.*". I guess that additional line is not too much of a problem