Thursday 11 December 2008

Passing enums into a constructor

Take this error:

binding.GrailsDataBinder Unable to auto-create type, 'create' method not found.

I came across this yesterday, and although the cause was documented, two of us managed to miss the crucial sentence in those docs for about an hour, causing much scratching of heads:

"my problem is that when I pass a Status enum to a constructor of some other class"

So, setting enum properties on a domain object is fine:

Burger canHaz = new Burger();
canHaz.flavour = Flavours.CHEESE;

Just not doing so via a constructor call:

Burger willNeverHaz = new Burger(flavour:Flavours.VEGETARIAN);

The original post I found is here:

http://www.nabble.com/Using-enums-gives-%22Unable-to-auto-create-type,-'create'-method-not-found%22-error-td18890306.html

and the JIRA bug report here:

http://jira.codehaus.org/browse/GRAILS-3314

Hopefully this will save someone else lots of head scratching! :o)

No comments: