我想生成这样的代码:
class B private constructor() : A {
companion object {
val instance: B by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
B()
}
}
}
使用 KotlinPoet:
private fun genCompanionObject() = TypeSpec.companionObjectBuilder()
.addProperty(PropertySpec.builder("instance", A::class.java).build()).build()
如何生成by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED)
?我在文档中找不到一些有用的 API 。