Java optional to kotlin nullable
reminder, java, kotlin, optional ·From this
stackoverflow forum, below code extends Optional
and adds a hande unwrap()
method that converts the java Optional
into a kotlin nullable object.
fun <T> Optional<T>.unwrap(): T? = orElse(null)
and then you can used like below:
val msg: Something? = optional.unwrap()