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

Methods from java.lang.Object shouldn't be considered abstract

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.0-rc-2
    • 2.2.0-rc-3
    • 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
      

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            melix Cédric Champeau
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: