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

size() (method) and size (property) behave inconsistently in different contexts

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 2.1.0
    • None
    • syntax
    • None

    Description

      I'm new to Groovy (coming from Java and Ruby) so part of this will be down to my understanding. However I think the following fails the principle of least surprise:

      > [1, 2].size()
      2
      > [1, 2].size
      2

      > ['foo': 42, 'bar': 43].size()
      2
      > ['foo': 42, 'bar': 43].size
      null

      > "hello".size()
      5
      > "hello".size
      ERROR groovy.lang.MissingPropertyException

      > (0..<5).size()
      5
      > (0..<5).size
      ERROR groovy.lang.MissingPropertyException

      (The above are the results I get when pasting into 'groovysh'.)

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            pjl Paul Lewis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: