Using Greclipse 4.4.0.v202112282355-e2009.
Consider this Java utility class:
package test70;
import java.util.List;
import java.util.function.BiConsumer;
public class Util {
public static <T> BiConsumer<String, ? super List<T>> batchFromIndividualPostProcessor(
final BiConsumer<String, ? super T> postProcessor) {
return (text, batch) -> {
for (final T element : batch)
postProcessor.accept(text, element);
};
}
}
and this Groovy class:
package test70
import groovy.transform.CompileStatic
@CompileStatic
class Test70 {
void foo() {
Util.batchFromIndividualPostProcessor { String text, Number number ->
number.toBigDecimal()
}
}
}
A compilation error is produced on number.toBigDecimal() because number is detected as Object rather than Number.
Please note that:
- this was compiling fine with some versions of Greclipse ago (cannot say exactly which one now)
- this compiles fine with Gradle/groovyc
- switching to
@CompileDynamic makes things work
I have other more complex use cases in my real-world project which I think are related to this same problem. It seems like Greclipse is simply ignoring now the type I'm declaring for closure arguments.
Using Greclipse 4.4.0.v202112282355-e2009.
Consider this Java utility class:
and this Groovy class:
A compilation error is produced on
number.toBigDecimal()becausenumberis detected asObjectrather thanNumber.Please note that:
@CompileDynamicmakes things workI have other more complex use cases in my real-world project which I think are related to this same problem. It seems like Greclipse is simply ignoring now the type I'm declaring for closure arguments.