Hi,
I have a problem running this code:
import groovy.transform.CompileStatic
import java.util.function.Function
@CompileStatic
class Test {
static void main(String[] args) {
// this code fails
Function<Integer, Integer> fct = { Integer n ->
-n
}
// this one works but it is too verbose
// Function<Integer, Integer> fct = ({ Integer n ->
// -n
// } as Function<Integer, Integer>)
println fct.apply(10)
}
}
The error:
Test.groovy: 9: [Static type checking] - Incompatible generic argument
types. Cannot assign java.util.function.Function <java.lang.Integer,
groovy.lang.Closure> to: java.util.function.Function <Integer, Integer>
@ line 9, column 36.
Function<Integer, Integer> fct = { Integer n ->
^
1 error
[Finished in 0.5s]
Is there a bug in groovy related to @CompileStatic or maybe I am missing
something else? I just don't want to write redundant code.
Thanks,
Mihai
--
View this message in context:
http://groovy.329449.n5.nabble.com/Static-type-checking-tp5735162.html
Sent from the Groovy Users mailing list archive at Nabble.com.