Created
July 29, 2012 05:06
-
-
Save fumokmm/3196189 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
interface Cat { | |
String mew() | |
} | |
class Zash implements Cat { | |
String mew(){ "雑種" } | |
} | |
class Nora implements Cat { | |
String mew(){ "野良" } | |
} | |
def scottish = [mew:{"すこてぃっしゅ"}] as Cat | |
Cat.metaClass { | |
def oldMew = Cat.metaClass.getMetaMethod('mew', [] as Class[]) | |
mew = {-> | |
"[Cat] ${oldMew.invoke(delegate, null)}" | |
} | |
} | |
Cat[] cats = [new Zash(), new Nora(), scottish] as Cat[] | |
for (c in cats) println c.mew() | |
// output ↓ | |
// [Cat] 雑種 | |
// [Cat] 野良 | |
// [Cat] すこてぃっしゅ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment