我使用從庫中的部分代碼:https://github.com/Netflix-Skunkworks/rewrite如何用lambda調用多個類似簽名的Kotlin方法?
當我調用它的方法之一,我遇到一個IDE錯誤:
None of the following functions can be called with the arguments supplied.
目標的方法有兩個類似的特徵:
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
}
}
在科特林調用代碼:
val unit: CompilationUnit =...
unit.refactor{ tx ->
doSomeThing()
}
這與調用拉姆達是OK在Java中:
CompilationUnit unit = ....
unit.refactor(tx -> {
doSomeThing()
});