Skip to content

Instantly share code, notes, and snippets.

@grimrose
Created November 27, 2012 13:06
Show Gist options
  • Save grimrose/4154146 to your computer and use it in GitHub Desktop.
Save grimrose/4154146 to your computer and use it in GitHub Desktop.
GroovyObject#invokeMethodのオーバーライドとMetaClass#invokeMethodの違い
package sample
class HogeBean {
Object invokeMethod(String name, Object args) {
println "invoke method $name, $args"
null
}
void debug() {
println "call debug."
}
void debug(info) {
println "call debug $info"
}
}
def sut = new HogeBean()
sut.debug("info")
sut.debug()
sut.debug("info", 10)
sut.target()
sut.target("info")
HogeBean.metaClass.invokeMethod { name, args ->
println "metaclass invoke $name, $args"
}
sut = new HogeBean()
println "*** metaclass invokeMethod ***"
sut.debug("info")
sut.debug()
sut.debug("info", 10)
sut.target()
sut.target("info")
call debug info
call debug.
invoke method debug, [info, 10]
invoke method target, []
invoke method target, [info]
*** metaclass invokeMethod ***
metaclass invoke debug, [info]
metaclass invoke debug, []
metaclass invoke debug, [info, 10]
metaclass invoke target, []
metaclass invoke target, [info]
@grimrose
Copy link
Author

「メソッドとしてのinvokeMethodと、metaClassのinvokeMethodの動きの違い」

「GroovyObject#invokeMethodのオーバーライドとMetaClass#invokeMethodの違い」
に変えました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment