Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.2.0-rc-2
-
None
-
None
Description
When determining if a type is a SAM-type, methods from java.lang.Object should be ignored. For example, the following class is not considered as a SAM-type:
interface Predicate<T> { boolean apply(T val) boolean equals(Object that) }
This example is a simplified version of Predicate from Guava. Basically, the equals method will always be implemented, so it shouldn't be considered abstract, even if it's defined explicitely in the interface. This prevents Closure from being automatically coerced to Predicate.
A simple script showing the problem:
@Grab('com.google.guava:guava:15.0') import com.google.common.base.Predicate static <T> boolean doAll(Iterator<T> itr, Predicate<T> predicate ) {} def itr = ['a','b'].iterator() doAll(itr) { it.length()>3 } // fails to coerce automatically