Skip to content

Instantly share code, notes, and snippets.

@bastman
Created February 14, 2019 08:45
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 bastman/00ff8e9487d2e72009e80f8b0951d33f to your computer and use it in GitHub Desktop.
Save bastman/00ff8e9487d2e72009e80f8b0951d33f to your computer and use it in GitHub Desktop.
Kotlin: fun Optional<T>.toNullable():T?
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