You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/01/27 10:43:00 UTC

[jira] [Updated] (GROOVY-6979) metaClass.getMetaMethod doesn't find method with Class as an argument

     [ https://issues.apache.org/jira/browse/GROOVY-6979?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King updated GROOVY-6979:
------------------------------
    Fix Version/s:     (was: 3.x)
                   4.x

> metaClass.getMetaMethod doesn't find method with Class as an argument
> ---------------------------------------------------------------------
>
>                 Key: GROOVY-6979
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6979
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: groovy-runtime
>    Affects Versions: 2.1.9, 2.2.2, 2.4.0-beta-1, 2.3.5
>            Reporter: Martin Schayna
>            Priority: Major
>             Fix For: 4.x
>
>
> Method with argument of type Class cannot be found by metaClass.getMetaMethod():
> {code:java}
> class A {
>     // cannot be found by getMetaMethod
>     def met1(Class clazz) {
>         println clazz.name
>     }
>     // a workaround
>     def met2(List<Class> clazz) {
>         println clazz.get(0).name
>     }
> }
> A.metaClass.invokeMethod = { name, args ->
>     def metaMethod = delegate.metaClass.getMetaMethod(name, args)
>     if (metaMethod) {
>         metaMethod.invoke(delegate, args)
>     } else {
>         println "Method $name not found on $delegate"
>     }
> }
> def a = new A()
> a.met1(A) // prints Method met1 not found on A@1c804...
> a.met2([A]) // prints A
> {code}
> It could be caused by ambiguous nature of *getMetaMethod* which accepts array of Object or Class as well, in case of Class as an argument it cannot find method correctly.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)