|
Groovy example source code file (OverloadInvokeMethodTest.groovy)
The Groovy OverloadInvokeMethodTest.groovy source codepackage groovy /** * @version $Revision: 1.4 $ */ class OverloadInvokeMethodTest extends GroovyTestCase { void testBug() { def value = foo(123) assert value == 246 } /** * Lets overload the invokeMethod() mechanism to provide an alias * to an existing method */ def invokeMethod(String name, Object args) { try { return metaClass.invokeMethod(this, name, args) } catch (MissingMethodException e) { if (name == 'foo') { return metaClass.invokeMethod(this, 'bar', args) } else { throw e } } } def bar(param) { return param * 2 } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy OverloadInvokeMethodTest.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.