Hi,
resending this to dev@ (originally users@). Would anyone know if what
I'm trying to achieve is possible? I think the compiler has enough
information and (using either @TypeChecked or @CompileStatic) it should
be possible to get the return type of Closure at runtime.
Thanks for any comments,
Jan
On 1/12/21 10:36 AM, Jan Lukavský wrote:
Hi,
I'm struggling with something I believe should be possible - when a
Closure is parsed at runtime, it should be possible to retrieve its
generic return type.
I have the following (in Java):
@Test
public void testClosureReturnTypeExtraction() {
String script = "def a = { 1L }";
Closure<?> closure = (Closure<?>) compile(script).run();
Class<?> returnType = retrieveReturnTypeFrom(closure); //
how to implement this??
assertEquals(Long.class, returnType);
}
What I cannot figure out is how to extract the type information from
the generated closure. I believe the type information should be there
(or at least it should be possible to put it there). So far, my best
attempt was, that I got that the type argument is "V". :-)
Any pointers would be appreciated.
Cheers,
Jan