Skip to content

Instantly share code, notes, and snippets.

@adam-arold
Created September 11, 2017 16:32
Show Gist options
  • Save adam-arold/7c3530e7257e161d475755dd4bc0c504 to your computer and use it in GitHub Desktop.
Save adam-arold/7c3530e7257e161d475755dd4bc0c504 to your computer and use it in GitHub Desktop.
Kotlin user without nulls
data class KotlinUserWithoutNulls(val firstName: String,
// this parameter can't be null
val lastName: String,
val addresses: List<Address> = listOf()) {
data class Address(val city: String)
companion object {
fun fetchFirstCity(user: KotlinUserWithNulls) =
user.addresses.first().city
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment