Created
January 31, 2018 10:39
-
-
Save bastman/87faa0e410d08f1650c319a331418665 to your computer and use it in GitHub Desktop.
Kotlin extension function to convert Java8 Optional<T> to Kotlin nullable 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
fun <T : Any> Optional<T>.toNullable(): T? { | |
return if (this.isPresent) { | |
this.get() | |
} else { | |
null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice! And the reverse.