Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.1.7
-
None
Description
The following code produces the compilation error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
bad.groovy: 20: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type Ifc
@ line 20, column 16.
Ifc ifc = Generator.create(Ifc)
^
1 error
import groovy.transform.CompileStatic import java.lang.reflect.Method interface Ifc { void method() } @CompileStatic class Generator { static <T> T create (Class<T> clazz) { return clazz.methods.collectEntries { Method method -> [ (method.name) : { println "${method.name} called"} ] }.asType(clazz) } } @CompileStatic class User { static void main() { Ifc ifc = Generator.create(Ifc) ifc.method() } } User.main()
Without the @CompileStatic on the User class, the code compiles and runs as expected.