How do I use Kotlinpoet to generate the following code?
data class Test (
@Id
var id: Long
) : Interface {
override fun primaryKey() : Serializable = this
}
How do I use Kotlinpoet to generate the following code?
data class Test (
@Id
var id: Long
) : Interface {
override fun primaryKey() : Serializable = this
}
You can try
FileSpec
.builder(packageName, actionName)
.addType(TypeSpec.classBuilder(actionName)
.primaryConstructor(FunSpec.constructorBuilder()
.addParameter(ParameterSpec.builder("aName", String::class.java)
.addAnnotation(Id::class.java)
.build())
.build()).build())
with Yrii‘s answer, you also need call
addProperty(PropertySpec.builder("id",Long::class).initializer("id").build())