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

The range interface should return the generic type T from getTo() and getFrom()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0.5
    • 2.1.0-beta-1
    • groovy-jdk
    • None

    Description

      The groovy.lang.Range type returns Comparable from getTo() and getFrom(). However, Range is a generic interface and the generic type T could be used instead. This is useful when using @TypeChecked or @CompileStatic as it allows groovy to infer the correct type.

      Here's a simple test case:

      @groovy.transform.CompileStatic
      def test(Range<Date> r) {
          println r.to.time
      }
      
      def now = new Date()
      test(now..now)
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            ataylor284 Andrew Taylor
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: