I saw Calling a groovy script from a java function using javax.script I guess with the runWithGroovyClassLoader can get a java class, java object and call its method with arguments. Though in the example its a no args example.
I a solution to be able to call type script. So my users enter type script in the front end. In the back end we call the script from within a Java function, passing it some state (arguments) of current txn from Java and then the type script returns a map / object back to calling java function