Type parameters are not available to static members (except in traits).
class C<T> {
private /*static*/ final Closure<T> noOpClosure = { T v -> return v }
}
You can use Closure.IDENTITY for this specific case.
________________________________
From: James Daugherty <[email protected]>
Sent: Friday, April 11, 2025 12:43 PM
To: [email protected] <[email protected]>
Subject: [EXT] Compilation issue between Groovy 3.0.21 & 3.0.23
External Email: Use caution with links and attachments.
Hello Everyone,
Grails recently had a bug report on one of the upgrades in 6.x.
https://github.com/apache/grails-core/issues/14130#issuecomment-2797619047<https://urldefense.com/v3/__https://github.com/apache/grails-core/issues/14130*issuecomment-2797619047__;Iw!!GFN0sa3rsbfR8OLyAw!YjXl7VcknY8JZsg8UKFdQl-3nyuCEAyrCRGt1gy33d31VYhj4VVckjQKzoMRPISo3PI4rC0PzM8LYwPdyaMULvVgjel7agI$>
I've narrowed down the issue to the groovy upgrade from 3.0.21 to 3.0.23. In
groovy 3.0.21 the following code compiles:
class GenericWrapper<T> {
private static final Closure<T> noOpClosure = { T v ->
return v }
private T obj
GenericWrapper(T obj) {
this.obj = obj
}
T transformObj() {
return noOpClosure.call(this.obj)
}
}
While in groovy 3.0.23 it fails to compile with:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
testing.groovy: 3: unable to resolve class T
@ line 3, column 31.
private static final Closure<T> noOpClosure = { T v -> return v }
^
testing.groovy: 3: unable to resolve class T
@ line 3, column 50.
al Closure<T> noOpClosure = { T v -> ret
^
2 errors
Is anyone aware of a known regression in this area?
Regards,
James