Created
December 12, 2013 11:13
-
-
Save mgdelacroix/7926451 to your computer and use it in GitHub Desktop.
Implement the asType method for a class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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