Skip to content

Instantly share code, notes, and snippets.

@Megamiun
Last active May 19, 2019 21:12
Show Gist options
  • Save Megamiun/8d3a968b62156750430f4af63ba48b0a to your computer and use it in GitHub Desktop.
Save Megamiun/8d3a968b62156750430f4af63ba48b0a to your computer and use it in GitHub Desktop.
Gists showing the difference of using the nullability resources from Kotlin
class PersonalInfo(val phone: String?)
class Person(val personalInfo: PersonalInfo?)
class PhoneGetter {
public String getPhone(Person person) {
if (person == null) return ""
val personalInfo = person.personalInfo
if (personalInfo == null) return ""
val phone = personalInfo.phone
if (phone == null) return ""
return phone
}
}
fun getPhone(person: Person?): String {
return person?.personalInfo?.phone ?: ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment