簡體   English   中英

Groovy類重寫了構造函數,為什么會缺少MissingMethodException?

[英]Groovy class overridden constructor, why MissingMethodException?

我有以下課程:

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

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

當我實例化它時:

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

我收到此錯誤:

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]

這個錯誤對我來說毫無意義,因為據我所知,構造函數被定義為使用兩個字符串,而我正在傳遞兩個字符串。

我是Groovy的新手,並且通過復制示例來達到這一目的。 我究竟做錯了什么?

調用構造函數時,缺少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