2
我知道我可以像這樣的Groovy類創建一個電話運營商:有沒有一個靜態的Groovy調用操作符?
class MyCallable {
int call(int x) {
2*x
}
}
def mc = new MyCallable()
assert mc(2) == 4
但我可以創造一個靜態調用的方法?
class MyStaticCallable {
static int call(int x) {
2*x
}
}
assert MyStaticCallable(2) == 4
非常感謝您的幫助!
非常感謝@tim_yates!我最終用'import static'僞裝了它。 –