Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2351

Varargs with overloaded methods

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.1-rc-3
    • Fix Version/s: 1.5
    • Component/s: class generator
    • Labels:
      None

      Description

      [code]
      class VarArgs {
      def method(Object... args)

      { println "method with Objects" }

      def method(Integer... args)

      { println "method with Integer" }

      }

      def a = new VarArgs()
      a.method(1, 2, 3, 4, 5)
      [/code]

      1/ The above code fails with the following exception:

      Caught: groovy.lang.MissingMethodException: No signature of method: VarArgsMethod.method() is applicable for argument types:
      (java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer) values:

      {1, 2, 3, 4, 5}

      at VarArgsMethod.invokeMethod(VarArgs.groovy)
      at VarArgs.run(VarArgs.groovy:14)
      at VarArgs.main(VarArgs.groovy)

      2/ If you change the method signatures to be Object[] and Integer[] respectively, the code still fails with the same error.

      3/ If you change the method signature from Object... (or Object[]) to be a type which is not a super type of Integer (f.e. String... the
      code will correctly run).

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              alexpopescu Alexandru Popescu
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: