I have the following code in Groovy 1.8.5 and to me it looks valid. Why does this give an error?
public enum Test
{
ONE("meep"), TWO("jeep"), THREE("sheep");
Test(String n)
{
this.n = n;
}
@Delegate String n;
}
println Test.ONE[1]
println Test.TWO[0]
Edit 1:
I have a number of enumerated objects, so I want to put them in an enum. Each value of the enum represents an instance of those objects so why not store them there? Now, groovy enables me to do, say Test.One.digits instead of Test.One.n.digitswhich is handier.
When i try to run it in eclipse i get Exception in thread "main" java.lang.NoClassDefFoundError which i interpret as the class not being compiled properly. I don’t have the compiler message at the time though… I’m working on it.
Edit 2:
I got the script to work here though… http://gppconsole.appspot.com/script/34001
So I guess case closed and the problem is not the code.
What error do you get?
works in Groovy 1.8.6… Though I’m not sure that adding a
@Delegateto an enum is a good thing to do (I need to think about it more)…What are you trying to achieve?