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

TupleConstructor should have only SOURCE retention policy

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.5
    • 2.5.0-alpha-1
    • xforms
    • None

    Description

      We originally gave TupleConstructor RUNTIME retention policy since it might provide a small amount of introspection information for future tools. But so far, as far as I know, it hasn't been used. Given that it makes certain usages impossible, I propose to put back to SOURCE retention policy. This will allow code such as shown below to be possible:

      import groovy.transform.*
      import java.awt.Color
      
      class Named {
          String name
      }
      
      @ToString(includeSuperProperties=true, ignoreNulls=true, includeNames=true, includeFields=true)
      @TupleConstructor(force=true, defaults=false)
      @TupleConstructor(force=true, defaults=false, includeFields=true)
      @TupleConstructor(force=true, defaults=false, includeSuperProperties=true)
      class Cat extends Named {
          int age
          private Color color
      }
      
      assert new Cat("Felix", 3).toString() == 'Cat(age:3, name:Felix)'
      assert new Cat(3, Color.BLACK).toString() == 'Cat(age:3, color:java.awt.Color[r=0,g=0,b=0])'
      assert new Cat(3).toString() == 'Cat(age:3)'
      

      Attachments

        Activity

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: