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

Type inference not working for Collections.sort()

    XMLWordPrintableJSON

Details

    Description

      In this example:

      import groovy.transform.TypeChecked
      
      doIt()
      
      @TypeChecked
      void doIt() {
          List<Integer> nums = [1, 2, 3, -2, -5, 6]
      //    nums.sort { a, b -> a.abs() <=> b.abs() }
          Collections.sort(nums, { a, b -> a.abs() <=> b.abs() })
      }
      

      the type checking fails on the closure arguments (no method abs() on type Object). Interestingly, it works fine for the line that's commented out.

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            pledbrook Peter Ledbrook
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: