Hi,
So, I had a difference of opinion with Marcin Erdmann on camera about
closure parameter type inference with functional interfaces. I said it
didn't work in my experience. Thankfully, Marcin worked out why my example:
import groovy.transform.TypeChecked
@TypeChecked
def someMethod() {
List<Integer> numbers = [1, 4, 56, 35]
Collections.sort(numbers, { a, b -> a.abs() <=> b.abs() })
}
doesn't compile. The problem is that Comparator, despite having the
@FunctionalInterface annotation, defines two methods: compare() and
equals(). Interestingly, {...} as Comparator works fine though.
So, does it make sense to add a special case for Comparator so that type
inference works? Or perhaps a special case for any interface that only has
one method that's not defined on Object as well?
Thanks,
Peter
--
Peter Ledbrook
t: @pledbrook
w: http://www.cacoethes.co.uk/