有没有办法获取在Groovy脚本中声明的类的反射数据,该脚本已经通过GroovyClassLoader parseClass方法进行了评估?
我究竟如何从java代码创建Customer实例?
package project
public class Customer extends Entity {
public String name
String description
Date updateDate
}
def run() {
Workflow workflow = new Workflow();
}
答案 0 :(得分:0)
GroovyClassLoader gcl = new GroovyClassLoader();
Class compiledClass = gcl.parseClass(src);
// usually we wait for "contract" class implemented in groovy, i.e Entity
Entity groovyEntity = (Entity ) compiledClass.newInstance();
// as yet, we don't know, implementation has name
String name = compiledClass.getName();