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
fun main() { | |
// You can do this | |
val assignment = null ?: false | |
val fromBlock = when(assignment) { | |
true -> true | |
false -> null | |
} ?: false | |
// Or this | |
val computed = if (fromBlock && assignment) { true } else { null } | |
// see the outputs |
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
fun main() { | |
println(null != null ?: false) | |
val first = null // we don't know the type of this guy | |
val second = null ?: false // this guy is a boolean! | |
println(first != second) | |
var notNullableGuy = first != second // this guy is a non nullable boolean | |
notNullableGuy = false // we can do this | |
println(notNullableGuy) | |
} |
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
fun main(args: Array<String>) { | |
println(null != null ?: false) | |
} |