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

Groovy should support 'as Interface' shorthand syntax on normal Objects not just Maps and Closures

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.7.1
    • 1.7.2, 1.8-beta-1
    • None
    • None

    Description

      The following code example should work:

      class Person {
          String first, last
          int compareTo(Object other) { other.first <=> first }
      }
      def people = [
          new Person(first:'Alex', last:'Smith'),
          new Person(first:'Zak', last:'Smith')
      ]
      def comparablePeople = people.collect{ it as Comparable }
      Collections.sort(comparablePeople)
      assert comparablePeople*.first == ['Zak', 'Alex']
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: