Idioms
Idioms
A collection of random and frequently used idioms in Kotlin. If you have a favorite idiom, contribute it. Do a pull request.
Creating DTOs (POJOs/POCOs)
data class Customer(val name: String, val email: String)
provides a Customer
class with the following functionality:
- getters (and setters in case of vars) for all properties
equals()
hashCode()
toString()
copy()
-
component1()
,component2()
, …, for all properties (see Data classes)
Default values for function parameters
fun foo(a: Int = 0, b: String = "") { ... }