简体   繁体   English

kotlin诗人中如何实现suspend关键字修改高阶函数

[英]How to implement the suspend keyword to modify higher-order functions in kotlin poet

I want to modify higher-order functions with the ”suspend“ keyword.我想用“suspend”关键字修改高阶函数。 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.不知道怎么下手,官网API查了很久也没找到类似的答案。 I hope the boss will give instructions!希望老板指点!

The answer has been found, it can be solved by LambdaTypeName.copy(suspending = true), the specific code is as follows:已经找到答案了,可以通过LambdaTypeName.copy(suspending = true)来解决,具体代码如下:

val lambdaTypeName = LambdaTypeName.get(returnType = responseBean)
                FunSpec.builder(it.methodName).addParameter(ParameterSpec.builder("io",lambdaTypeName.copy(suspending = true)).build())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM