4
任何人都知道为什么下面的代码不起作用?Kotlin解包函数编译器错误
private fun wrapLogIfNeeded(buildMessageOnCurrentThread: Boolean, log:() -> String):() -> String
return if(buildMessageOnCurrentThread) {
val message = log() // Type mismatch: Required() -> String Found: Unit
{ message }
}
else {
log
}
}
但这:
private fun wrapLogIfNeeded(buildMessageOnCurrentThread: Boolean, log:() -> String):() -> String
return if(buildMessageOnCurrentThread) {
val message = lazy { log() }.value
{ message }
}
else {
log
}
}
到分号,可以更换拉姆达'{消息}'与[匿名功能](HTTPS:
要解决它,可以添加一个分号// kotlinlang。 org/docs/reference/lambdas.html#anonymous-functions):'fun()= message'。 – mfulton26