Groovy Call Closing a Java Class - Will It Compile?

I have some old Java code inside which I would call groovy Closure.

Is this something Java / groovy cross compiler can handle? I suspect that it compiles Java first, but does it do another pass through the groovy bytecode to resolve all java links.

Or do I need to compile the class with closure first in jar so that I can access it from Java?

+3
source share
2 answers

I see this for mixing Java and Groovy:
Mixed Java and Groovy Applications

Java/ Groovy. . , , Java, . / Groovy.

+2

- , , , SjB Java, groovy.

java:

interface decorator {
    public String decorate(String in) ;
}

Groovy:

class GroovyDecorator implements decorator {
    public String decorate(String in) {
        return "foo";
    }
}

, Java, :

...
public void javaFunc(someObject someStuff, decorator d) {
    // do some stuff
    d.decorate("input string");
}

Groovy:

GroovyDecorator gd = new GroovyDecorator() ;
javaFunc(someStuff, gd) ;

, , groovy, , .

, .groovy . GroovyDecorator, grails, .

0

Source: https://habr.com/ru/post/1724594/


All Articles