Groovy
  1. Groovy
  2. GROOVY-4999

Runtime error on static overloaded mixin method

    Details

      Description

      I have a class with static utility methods. I have done 'mixin' this class into another class using @Mixin annotation and then while calling static overloaded method I give runtime error.

      Utility class:

      class UtilClass {
          public void callClassOverloadedMethod(String s) {
              System.out.println("callClassOverloadedMethod(String)");
          }
          public void callClassOverloadedMethod(String s, Object o) {
              System.out.println("callClassOverloadedMethod(String, Object)");
          }
          public static void callStaticOverloadedMethod(String s) {
              System.out.println("callStaticOverloadedMethod(String)");
          }
          public static void callStaticOverloadedMethod(String s, Object o) {
              System.out.println("callStaticOverloadedMethod(String, Object)");
          }
      }
      

      Main class:

      @Mixin(UtilClass)
      class MainClass {
          public static void main(String []s) {
              MainClass mc = new MainClass()
              mc.callMixinMethods()
          }
      
          void callMixinMethods() {
              callClassOverloadedMethod("")
              callStaticOverloadedMethod("")
          }
      }
      

      Run command:

      groovy -cp . MainClass
      

      Error:

      Caught: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method callStaticOverloadedMethod() to invoke from this list:
        public static void UtilClass#callStaticOverloadedMethod(java.lang.String)
        public static void UtilClass#callStaticOverloadedMethod(java.lang.String, java.lang.Object)
              at MainClass.callMixinMethod(MainClass.groovy:20)
              at MainClass.main(MainClass.groovy:12)
      

      Please fix this trouble, it prevent me to write code and tests.

      1. Patch_Master.diff
        2 kB
        Roshan Dawrani

        Activity

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Anton Spirin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development