Reputation: 41
I want to modify higher-order functions with the ”suspend“ keyword. The following is what I want:
public fun login(io: suspend () -> ResLogin): Unit {}
I tried to use:
val lambdaTypeName = LambdaTypeName.get(returnType = responseBean)
But get the following code:
public fun login(io: () -> ResLogin): Unit {}
I don’t know how to start, and the official website API has been checked for a long time and I haven’t found a similar answer. I hope the boss will give instructions!
Upvotes: 2
Views: 236
Reputation: 41
The answer has been found, it can be solved by LambdaTypeName.copy(suspending = true), the specific code is as follows:
val lambdaTypeName = LambdaTypeName.get(returnType = responseBean)
FunSpec.builder(it.methodName).addParameter(ParameterSpec.builder("io",lambdaTypeName.copy(suspending = true)).build())
Upvotes: 2