Type-Safe Builders
suggest changeRemarks
A type-safe builder is a concept, rather than a language feature, so it is not strictly formalized.
A typical structure of a type-safe builder
A single builder function usually consists of 3 steps:
- Create an object.
- Execute lambda to initialize the object.
- Add the object to structure or return it.
Type-safe builders in Kotlin libraries
The concept of type-safe builders is widely used in some Kotlin libraries and frameworks, eg.:
- Anko
- Wasabi
- Ktor
- Spec
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents