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

Static type checker does not recognize closure input parameter when implementing an interface with a map

    XMLWordPrintableJSON

Details

    Description

      Consider the following Groovy class:

      package e
      import groovy.transform.TypeChecked;
      
      @TypeChecked
      class E {
      	
      	interface MyInt {
      		String doSomething(String text)
      	}
      	
      	static void main(String[] args) {
      		MyInt impl = [
      			doSomething: { it.toUpperCase() }
      			] as MyInt
      		println impl.doSomething('foo')
      	}
      }
      

      The compiler complains that:

      Groovy:[Static type checking] - Cannot find matching method java.lang.Object#toUpperCase(). Please check if 
       the declared type is right and if the method exists.
      

      However I think Groovy should be smart enough to recognize that it is of type String inside the closure.

      Attachments

        Activity

          People

            emilles Eric Milles
            mauromol Mauro Molinari
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: