简体   繁体   中英

How to return function in kotlin poet

I'm using KotlinPoet for annotation processing, but I've got an issue. I need return function in generated class, but I'm not sure that KotlinPoet can do it? If you have some experience, please help me.

That I can do:

fun test(): String = ...

That I need to do

fun test(): () -> String = ...

ClassNameTypeName相似,可以使用LambdaTypeName创建不带参数且String返回类型的函数类型:

val type = LambdaTypeName.get(returnType = String::class.asTypeName())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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