简体   繁体   English

Groovy类重写了构造函数,为什么会缺少MissingMethodException?

[英]Groovy class overridden constructor, why MissingMethodException?

I have the following class: 我有以下课程:

@groovy.transform.InheritConstructors
class PythonBuild {
    def basePath
    def branchName

    PythonBuild(String basePath, String branchName) {
        // stuff
    }
}

when I instantiate it: 当我实例化它时:

master = PythonBuild('Python-Backend/+MASTER/', 'master')

I get this error: 我收到此错误:

groovy.lang.MissingMethodException: No signature of method:
Script1.PythonBuild() is applicable for argument types:
(java.lang.String, java.lang.String) values: [Python-Backend/+MASTER/, master]

This error makes no sense to me since, as far as I can tell, the constructor is defined as taking two strings and I am passing two strings. 这个错误对我来说毫无意义,因为据我所知,构造函数被定义为使用两个字符串,而我正在传递两个字符串。

I am new to Groovy and have got this far by copying examples. 我是Groovy的新手,并且通过复制示例来达到这一目的。 What am I doing wrong? 我究竟做错了什么?

new keyword missed, while invoking constructor. 调用构造函数时,缺少new关键字。

@groovy.transform.InheritConstructors
class PythonBuild {    
    def basePath     
    def branchName     
    def PythonBuild(String basePath, String branchName) { } 
}


def master = new PythonBuild('Python-Backend/+MASTER/', 'master')


println(master)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM