Created
September 20, 2017 03:45
-
-
Save mateisuica/634c0ab5151617945df0e5b4a07ae7d1 to your computer and use it in GitHub Desktop.
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
// 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