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

sample code in javadoc of Map#spreadMap() don't works

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.8-rc-4
    • groovy-jdk
    • None

    Description

      At the GDK document of Map#toSpreadMap(),

      http://groovy.codehaus.org/groovy-jdk/java/util/Map.html#toSpreadMap()

      says:

      For examples, if there is defined a function like as

      def fn(a, b, c, d)

      Unknown macro: { return a + b + c + d }

      , then all of the following three have the same meaning.
      println fn(a:1, [b:2, c:3].toSpreadMap(), d:4)
      println fn(a:1, *:[b:2, c:3], d:4)
      println fn(a:1, b:2, c:3, d:4)

      I think there are at least 2 problems here.

      1) fn should take Map parameter like:

      def fn(Map m) { return m.a + m.b + m.c + m.d }

      2) I changed it in 1) way but I get following error at the line calling toSpreadMap().

      Caught: groovy.lang.MissingMethodException: No signature of method: d.fn() is applicable for argument types: (java.util.LinkedHashMap, groovy.lang.SpreadMap) values: [[a:1, d:4], [:]]
      Possible solutions: fn(java.util.Map), run(), run(), any(), run(java.io.File, [Ljava.lang.String, any(groovy.lang.Closure)
      at d.run(d.groovy:3)

      Attachments

        Activity

          People

            paulk Paul King
            uehaj UEHARA Junji
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: