I am looking at some Java interop stuff.
To keep things simple, I am working with a application SDK which is in Java, and it accepts some JSR-223 loaded scripts.
The primary target is Groovy script and at the moment. Groovy needs to pass a Closure that is processed essentially as a callback for initialisation reasons.
The Groovy is loaded early, but the initialisation happens late - this happens as it is a Spring app, so bean registration needs to happen early, but initialisation occurs only after bean registration.
That said, it's not that I dislike Groovy, but let's face it, we are all here because we like Kotlin more, or at a minimum dislike Groovy just a little more than Kotlin 😉 K
I don't really have the means to test, but is it one possible, and two what Kotlin & Java types are involved, to be able to pass around some form of Closure like object from Kotlin, that can be invoked Java side?
As noted, right now
groovy.lang.Closure
is being accepted by Java to allow callback to the script. It does also allow processing of a
javax.script.Invocable
.
I don't have much control over the SDK - but would certainly try and influence it with justification.
So if I wanted to say pass in an instance of a Kotlin function type, i.e. Lambda, anon-function or callable reference.
What would be the types that Java needs to handle? Are they different say between a Lambda and callable ref?
I know I could just specifically generate an Object that implements Callable, thus knowing the types by default, but that seems like forcing something over using the more natural - and readable - kotlin syntax