Created
May 1, 2011 14:33
-
-
Save nobeans/950540 to your computer and use it in GitHub Desktop.
sample of use
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
class Hoge { | |
static String hoge(String delegate) { | |
return "HOGE: $delegate" | |
} | |
static String foo(String delegate, String param) { | |
return "FOO: $delegate ($param)" | |
} | |
static String bar(Class<String> string) { | |
return "BAR" | |
} | |
static String baz(Class<String> string) { | |
if (!string?.isAssignableFrom(String)) { | |
throw new ClassCastException("String only") | |
} | |
return "BAZ" | |
} | |
} | |
use(Hoge) { | |
println "A" | |
println "A".hoge() | |
println "A".foo() | |
println "A".foo("BAR") | |
println String.bar() | |
println Integer.bar() // 誤爆 | |
println String.baz() | |
println Integer.baz() // ClassCastException: String only | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment