Last active
May 19, 2019 21:12
-
-
Save Megamiun/8d3a968b62156750430f4af63ba48b0a to your computer and use it in GitHub Desktop.
Gists showing the difference of using the nullability resources from Kotlin
This file contains 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
class PersonalInfo(val phone: String?) | |
class Person(val personalInfo: PersonalInfo?) |
This file contains 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
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 | |
} | |
} |
This file contains 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
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