Skip to content

Instantly share code, notes, and snippets.

@mateisuica
Created September 20, 2017 03:45
Show Gist options
  • Save mateisuica/634c0ab5151617945df0e5b4a07ae7d1 to your computer and use it in GitHub Desktop.
Save mateisuica/634c0ab5151617945df0e5b4a07ae7d1 to your computer and use it in GitHub Desktop.
// Kotlin
var bob : User? = null
...
fun printBob() {
someOutput(bob?.name)
someOutput(bob?.surname)
if(bob?.age == 5) { // does this even work? I need to null check separately, right?
doSomeMoreStuff(bob?.dateOfBirth)
}
}
// Or maybe I should use !! ?
fun printBob() {
someOutput(bob!!.name)
someOutput(bob!!.surname)
if(bob!!.age == 5) {
doSomeMoreStuff(bob!!.dateOfBirth)
}
}
//Swift
var bob : User? = null
func printBob() {
if let notNullBob = bob {
someOutput(notNullBob.name)
someOutput(notNullBob.surname)
if(notNullBob.age == 5) {
doSomeMoreStuff(notNullBob.dateOfBirth)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment