Kotlin
Optional API
Source: https://4comprehension.com/kotlins-java-util-optional-equivalents/
val x: Int? = 7 // ofNullable()
val result = x
?.let { ... } // map()
?.takeIf { ... } // filter()
?: 42 // orElseGet()
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
Source: https://4comprehension.com/kotlins-java-util-optional-equivalents/
val x: Int? = 7 // ofNullable()
val result = x
?.let { ... } // map()
?.takeIf { ... } // filter()
?: 42 // orElseGet()