使用 Java 找不到匹配的构造函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27936305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:39:55  来源:igfitidea点击:

Could not find matching constructor using Java

javagroovy

提问by Shaik Nizam Ali

I'm trying to call a constructor in a groovy file. I've a constructor like

我正在尝试在 groovy 文件中调用构造函数。我有一个像这样的构造函数

public class CreditCardDocumentImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements creditcard.CreditCardDocument
{
    // Constructor
    public CreditCardDocumentImpl(org.apache.xmlbeans.SchemaType sType)
    {  
        super(sType);
    }
}

When I try to access the constructor by calling ,

当我尝试通过调用访问构造函数时,

// Call the constructor
CreditCardDocument creditCardDocument = new CreditCardDocumentImpl(SchemaType);

It doesn't allow me

它不允许我

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: creditcard.impl.CreditCardDocumentImpl(java.lang.Class)

Any ideas would be greatly appreciated.

任何想法将不胜感激。

回答by Dongqing

You should pass an instanceof SchemaType, not the classitself.

您应该传递SchemaType的实例,而不是本身。

CreditCardDocument creditCardDocument = new CreditCardDocumentImpl(new SchemaType());