简体   繁体   English

Groovy:如何定义可使用参数调用的 java 并使其可用于 groovy Z2591C98B70119B519E18

[英]Groovy: How to define a java callable with parameters and make it available to groovy shell?

I would like to implement a Groovy interface that takes parameters and returns a result in java and make it available in GroovyShell.我想实现一个 Groovy 接口,它接受参数并在 java 中返回结果,并使其在 GroovyShell 中可用。 However Callable, GroovyCallacble do not take any parameters so they are wrong for my purposes.但是 Callable、GroovyCallacble 不接受任何参数,因此它们对于我的目的是错误的。

Any tips would be appreciated.任何提示将不胜感激。

It is possible to create a "Closure" sub class in java and bind it to the Bindings accompanying a GroovyShell.可以在 java 中创建“闭包”子 class 并将其绑定到 GroovyShell 随附的绑定。 Once this is done it is possible to execute the Closure from groovy at the bound name.完成此操作后,可以在绑定名称处从 groovy 执行闭包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM