Last active
October 24, 2019 06:51
-
-
Save mirokolodii/e62903e801ff2f1441a0e6dfe487d06a to your computer and use it in GitHub Desktop.
Switch to Kotlin #2.8
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
var nonNullInt = 1 | |
val nullInt: Int? = null | |
// 1. Error | |
nonNullInt = nullInt // Error: type mismatch | |
// 2. Valid | |
if (nullInt != null) { | |
/* Here is used a smart cast (one of Kotlin compiler's feature), | |
which casts Int? to Int automatically */ | |
nonNullInt = nullInt | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment