【问题标题】:Variable must be initialized变量必须初始化
【发布时间】:2021-03-29 15:20:34
【问题描述】:

我有一个类型别名,例如: typealias FetchCompletionHandler = (FetchResponse?, FetchError?) -> Unit 我必须将其作为参数传递给函数,但出现“必须初始化变量”的错误。 我已将变量声明如下: val fetchCompletionHandler: FetchCompletionHandler

【问题讨论】:

标签: android kotlin


【解决方案1】:

要使用fetchCompletionHandler,您需要使用 lambda 函数对其进行初始化

val fetchCompletionHandler: FetchCompletionHandler = {response, error ->
  //handle response or error here

}

调用fetchCompletionHandler

fetchCompletionHandler(response, error)

【讨论】:

    猜你喜欢
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多