Created
January 12, 2018 16:52
-
-
Save ivan-osipov/7be021c005b1c0beddda8b0a7fc0dabd to your computer and use it in GitHub Desktop.
KotlinPoet example: simple class with lateinit property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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