Created
September 11, 2017 16:31
-
-
Save adam-arold/a4ffb5d187a893ac59af7b349ef399b3 to your computer and use it in GitHub Desktop.
Kotlin user with nulls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class KotlinUserWithNulls(val firstName: String?, | |
// String? means that it is either a String object or a null | |
val lastName: String?, | |
val addresses: List<Address> = listOf()) { | |
data class Address(val city: String?) | |
companion object { | |
fun fetchFirstCity(user: KotlinUserWithNulls?): String? { | |
user?.addresses?.forEach { it.city?.let { return it } } | |
return null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment