Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
-
Patch
Description
The provided patch adds String to Enum coercion. Basically, when trying to affect a string to a variable expecting an enumeration type, Groovy fails with a cast error. The patch allows coercing (G)String to the expected enumeration type. It's useful since it allows avoiding noisy imports when you already know the possible enum values.
Patch is applicable to both trunk and 1.7.X branch and adds this test in CastTest.groovy :
void testCastEnum() { CastEnum val; val = 'value1' assert val == val.value1 def i=2 val = "value$i" assert val == val.value2 } enum CastEnum { value1, value2 }