Skip to content

Instantly share code, notes, and snippets.

@ivan-osipov
Created January 12, 2018 16:52
Show Gist options
  • Save ivan-osipov/7be021c005b1c0beddda8b0a7fc0dabd to your computer and use it in GitHub Desktop.
Save ivan-osipov/7be021c005b1c0beddda8b0a7fc0dabd to your computer and use it in GitHub Desktop.
KotlinPoet example: simple class with lateinit property
fun main(args: Array<String>) {
val userClass = ClassName("example", "User")
val file = FileSpec.builder("example", "model")
.addType(TypeSpec.classBuilder(userClass)
.addProperty(PropertySpec
.varBuilder("name", String::class, KModifier.LATEINIT)
.build())
.build())
.build()
file.writeTo(System.out)
}
/*
//results of class generation
package example
import kotlin.String
class User {
lateinit var name: String
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment