//AGroovyClass.groovy
class AGroovyClass {
def useClosure(closure) {
println "Calling closure"
closure()
}
def passToClosure(int value, closure) {
println "Simply passing $value to the given closure"
closure(value)
}
}
//UseAGroovyClass.java
public class UseAGroovyClass {
public static void main(String[] args) {
AGroovyClass instance = new AGroovyClass();
Object result = instance.useClosure(new Object() {
public String call() {
return "You called from Groovy!";
}
});
System.out.println("Received: " + result);
}
}
#编译运行
groovyc -j UseAGroovyClass.java AGroovyClass.groovy
java -classpath $GROOVY_HOME/embeddable/groovy-all-2.4.5.jar:. UseAGroovyClass
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于