Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2503 MOP 2.0 design inflluencing issues
  3. GROOVY-6979

metaClass.getMetaMethod doesn't find method with Class as an argument

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.1.9, 2.2.2, 2.4.0-beta-1, 2.3.5
    • 4.x
    • groovy-runtime
    • None

    Description

      Method with argument of type Class cannot be found by metaClass.getMetaMethod():

      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
      
      

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            mschayna Martin Schayna
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: