变量必须被初始化

时间:2021-03-29 15:20:34

标签: android kotlin

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

1 个答案:

答案 0 :(得分:0)

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

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

}

调用fetchCompletionHandler

fetchCompletionHandler(response, error)