Created
November 27, 2012 13:06
-
-
Save grimrose/4154146 to your computer and use it in GitHub Desktop.
GroovyObject#invokeMethodのオーバーライドとMetaClass#invokeMethodの違い
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
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") |
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
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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
「メソッドとしてのinvokeMethodと、metaClassのinvokeMethodの動きの違い」
を
「GroovyObject#invokeMethodのオーバーライドとMetaClass#invokeMethodの違い」
に変えました。