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

Dynamically added methods seem to need an arrow in the closure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.5
    • 1.5
    • None
    • None
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: