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

Dynamically added methods seem to need an arrow in the closure

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.5
    • Component/s: None
    • Labels:
      None
    • Environment:
      Java 6 on 32 bit MS Vista

      Description

      The closure arrow for a dynamically added method seems to be necessary, which seems a bit inconsistent with usual closure usage. E.g. this works:

      class Book

      { String title }

      Book.metaClass.toString = { -> title }

      def b = new Book(title:"The Stand")

      assert "The Stand" == b.toString()

      But this doesn't:

      class Book { String title }

      Book.metaClass.toString =

      { title }

      def b = new Book(title:"The Stand")

      assert "The Stand" == b.toString()

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              meyrickkirby Meyrick Kirby
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: