Types
View MarkdownReference a type
Section titled “Reference a type”Use type {} where a builder expects a type. Inside it, use reference() with the type’s name. Set nullable = true in the same block to add ?.
import com.alexstyl.prosakt.ktFile
val source = ktFile { ktValue("nickname") { type { reference("String") nullable = true } initializer { literal(null) } }}Generated Kotlin:
val nickname: String? = nullAdd type arguments
Section titled “Add type arguments”Use argument {} inside a type block to add a generic type argument. Use type {} inside the argument block to describe that argument’s type.
import com.alexstyl.prosakt.ktFile
val source = ktFile { ktValue("names") { type { reference("kotlin.collections.List") argument { type { reference("String") } } } initializer { call("kotlin.collections.emptyList") { } } }}Generated Kotlin:
val names: List<String> = emptyList()Use fully qualified names for types outside the generated package. Prosa.kt collects the required imports automatically; see Imports.