“使用提供的参数不能调用以下功能”-为什么?

时间:2020-09-22 15:28:28

标签: kotlin lambda type-inference

下面的代码由于带有红色下划线的check

而无法编译

enter image description here

为lambda参数类型添加了屏幕截图,代码:

handledExceptions.forEach { exceptionClass ->
    exceptionClassToHandler.compute(exceptionClass.java) { clazz, existingHandler ->
        check(null == existingHandler) { "There's already a handler registered for ${clazz.name}" }
        { e: Throwable -> handlerMethod.invoke(bean, exceptionClass.java.cast(e)) }
    }
}

要求赔偿的

None of the following functions can be called with the arguments supplied: 
[ERROR] public inline fun check(value: Boolean): Unit defined in kotlin
[ERROR] public inline fun check(value: Boolean, lazyMessage: () -> Any): Unit defined in kotlin

如果我注释掉check,代码可以很好地编译。

(或替换为

if(existingHandler != null){
    throw IllegalStateException("There's already a handler registered for ${clazz.name}")
}

我觉得我缺少明显的东西。为什么支票无法编译,我该怎么办?

0 个答案:

没有答案