Monday, November 5, 2012

Groovy Enums

Found a neat trick for matching a String back to its enum. For instance if we have the following enum

public enum Status {
INBOX { public String toString() {"Inbox"}},
NEXT { public String toString() {"Next Action"}},
SOMEDAY { public String toString() {"Someday"}} }
 So if you had a String and wanted to match the enum it is as easy as

def a = "Inbox" as Status

No comments:

Post a Comment