Skip to content

Instantly share code, notes, and snippets.

@mirokolodii
Last active October 24, 2019 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirokolodii/e62903e801ff2f1441a0e6dfe487d06a to your computer and use it in GitHub Desktop.
Save mirokolodii/e62903e801ff2f1441a0e6dfe487d06a to your computer and use it in GitHub Desktop.
Switch to Kotlin #2.8
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