我有一個方法,像這樣怎樣一個布爾值傳遞給方法用一個變量名
def uploadFile(String fileName, boolean performCleanup = false) {
//upload file
if (performCleanup == true) {
//delete local file
}
}
我把這種方法有兩種方式:
uploadFile("/some/path/to/file.txt")
uploadFile("/some/path/to/file.txt", true)
在第二種情況下,爲了更好的可讀性,我想傳遞一個變量名, st通過true
的意義是什麼。
喜歡的東西,uploadFile("/some/path/to/file.txt", performCleanup: true")
這可能嗎?
也許[這](http://mrhaki.blogspot.com/2009/09 /groovy-goodness-named-parameters-are.html)文章將會有所幫助。 – Opal