Skip to content

Instantly share code, notes, and snippets.

@mgdelacroix
Created December 12, 2013 11:13
Show Gist options
  • Save mgdelacroix/7926451 to your computer and use it in GitHub Desktop.
Save mgdelacroix/7926451 to your computer and use it in GitHub Desktop.
Implement the asType method for a class
Object asType(Class type) {
switch (type) {
case String:
return this.toString()
break
case Integer:
return this.toInteger()
break
case File:
return new File(this.path)
break
default:
throw new IllegalArgumentException("Can't convert to type: $type.simpleName")
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment