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

calls to category methods (written in Groovy) don't recognise default parameters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0-JSR-6
    • 1.1-rc-3
    • None
    • None
    • JRE 1.5.0_07 on Windows XP prof edn

    Description

      When calling a method defined in a category written in Groovy, default parameters aren't recognised. An example...

      class ExtendedJoin{
      static String join(Collection self, String separator, int perLine, String lineSeparator= '\r\n'){
      def buffer= new StringBuffer(), first= true, i=0
      if(separator == null) separator= ''
      self.each{
      if(first) first= false else buffer<< separator
      if( i >perLine)

      { buffer<< lineSeparator; i=0 }

      buffer<< it
      i += it.size()
      }
      buffer.toString()
      }
      }

      use(ExtendedJoin){
      //this one works OK...
      println( ['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'].join(' ',20,'\r\n') )

      //but this one doesn't pick up the default param value...
      println( ['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'].join(' ',20) )
      //Caught: groovy.lang.MissingMethodException: No signature of method java.util.ArrayList.join()
      //is applicable for argument types: (java.lang.String, java.lang.Integer) values:

      {" ", 20}

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            gavingrover Gavin Grover
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: