【发布时间】:2016-01-31 19:31:55
【问题描述】:
我正在尝试以最好的“Groovy 方式”做事。 检查参数类型的最佳方法是什么(关于性能和“Groovy-way”)?我想到了 2 个实现:
def deploy(json) {
if (!(json instanceof String) && (json instanceof File)) {
json = json.text
} else {
throw new IllegalArgumentException('argument type mismatch – \'json\' should be String or File')
}
// TODO
}
或
def deploy(File json) {
deploy(json.text)
}
def deploy(String json) {
// TODO
}
谢谢:)
【问题讨论】:
-
第二个。如果您的方法必须采用类型,请声明该类型。如果它返回一个类型,也要声明它
标签: java groovy method-signature