Created
February 14, 2019 08:45
-
-
Save bastman/00ff8e9487d2e72009e80f8b0951d33f to your computer and use it in GitHub Desktop.
Kotlin: fun Optional<T>.toNullable():T?
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
import java.util.* | |
fun <T : Any> Optional<T>.toNullable(): T? = when (isPresent) { | |
true -> get() | |
false -> null | |
} | |
fun foo(x:Optional<Int>):Int? = x.toNullable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment