在这个问题中,我感到困惑,因为我认为我们可以将参数传递给没有括号的方法.实际上,您可以将参数作为逗号分隔列表传递给类似的方法:
task ListOfStrings(type: ExampleTask) {
//TheList 'one', 'two', 'three' // doesn't work
theList 'one', 'two', 'three'
}
public class ExampleTask extends DefaultTask {
//public void TheList(Object... theStrings) {
// theStrings.each { println it }
//}
public void theList(Object... theStrings) {
theStrings.each { println it }
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码有效,因为方法名称是camelCase.当使用TitleCase的方法名称(上面已注释掉)时,gradle会抛出一个错误:
build file '/tmp/build.gradle': 16: unexpected token: one @ line 16, column 13.
TheList 'one', 'two', 'three'
^
Run Code Online (Sandbox Code Playgroud)
SO,问题是,"为什么的方法名此事的情况?" 总之,导致这种行为的原因是什么?这是一个惯例吗?如果是这样,它在哪里记录?