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

Allow to omit square brackets in annotations when list has just one element (similar to Java)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.4
    • 1.6-beta-1
    • syntax
    • None

    Description

      Let's say we have the following enum declaration (in Java):

      @interface Person {
      String[] friends();
      }

      In Java, curly braces may be omitted if a person has just one friend:

      @Person(friends="Joe")
      class Jane {}

      In Groovy, this gives a compile error:
      Annotation list attributes must use Groovy notation [el1, el2]

      Of course @Person(friends=["Joe"]) still works, but it would be nice if Groovy also supported the abbreviated syntax.

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              pniederw Peter Niederwieser
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: