使用Groovy类的构造函数时,我遇到问题.
我在DataGroovy的文件中有一个Data Data类,内部有一个ContentEntry类.我想从Data方法初始化ContentEntry实例:
static void initContent(nid,uid) { curContent = new ContentEntry() curContent.nid = nid; curContent.uid = uid; }
ContentEntry定义为:
class ContentEntry { public int nid,uid private tags = [:] public ContentEntry() { } ContentEntry(int nid,int uid) { this.nid = nid this.uid = uid } //omitted rest of the class
但是当运行该项目时,它会给我以下错误:
Exception in thread "main" org.codehaus.groovy.runtime.Metaclass.MethodSelectionException: Could not find which method <init>() to invoke from this list: public it.softit.Data$ContentEntry#<init>(it.softit.Data,int,int) public it.softit.Data$ContentEntry#<init>(it.softit.Data)