KotlinPoet 1.0 is here!

Egor Andreevich
Dec 14, 2018 · Unlisted

Hello World, KotlinPoet! 👋

class Greeter(val name: String) {
fun greet() {
println("Hello, $name")
}
}
fun main(vararg args: String) {
Greeter(args[0]).greet()
}
val greeterClass = ClassName("", "Greeter")
val file = FileSpec.builder("", "HelloWorld")
.addType(TypeSpec.classBuilder("Greeter")
.primaryConstructor(FunSpec.constructorBuilder()
.addParameter("name", String::class)
.build())
.addProperty(PropertySpec.builder("name", String::class)
.initializer("name")
.build())
.addFunction(FunSpec.builder("greet")
.addStatement("println(%P)", "Hello, \$name")
.build())
.build())
.addFunction(FunSpec.builder("main")
.addParameter("args", String::class, VARARG)
.addStatement("%T(args[0]).greet()", greeterClass)
.build())
.build()
file.writeTo(System.out)

Square Corner Blog

Buying and selling sound like simple things - and they should be. Somewhere along the way, they got complicated. At Square, we're working hard to make commerce easy for everyone.

Thanks to Jesse Wilson.

Unlisted

Egor Andreevich

Written by

Android at Square Cash

Square Corner Blog

Buying and selling sound like simple things - and they should be. Somewhere along the way, they got complicated. At Square, we're working hard to make commerce easy for everyone.