简体   繁体   中英

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. What am I doing wrong?

new keyword missed, while invoking constructor.

@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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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