【发布时间】:2017-04-13 10:27:01
【问题描述】:
我正在使用这个库中的一些代码:https://github.com/Netflix-Skunkworks/rewrite
当我调用它的一个方法时,我遇到了一个 IDE 错误:
以下函数均不能使用提供的参数调用。
目标方法有两个相似的签名:
data class CompilationUnit(...){
fun refactor() = Refactor(this)
fun refactor(ops: Refactor.() -> Unit): Refactor {
val r = refactor()
ops(r)
return r
}
fun refactor(ops: Consumer<Refactor>): Refactor {
val r = refactor()
ops.accept(r)
return r
}
}
Kotlin 中的调用代码:
val unit: CompilationUnit =...
unit.refactor{ tx ->
doSomeThing()
}
而这个使用 lambda 的调用在 Java 中是可以的:
CompilationUnit unit = ....
unit.refactor(tx -> {
doSomeThing()
});
【问题讨论】:
标签: java kotlin higher-order-functions overload-resolution