This object provides extension methods that convert between Scala Option and Java Optional
types.
This object provides extension methods that convert between Scala Option and Java Optional
types.
It differs from the JVM version as in it does not provide any conversions for the Optional primitive type
wrappers which are available in the JDK but not in Scala-JS or Scala-Native.
Scala Option is extended with a toJava method that creates a corresponding Optional.
Java Optional is extended with a toScala method.
Example usage:
import scala.jdk.OptionConverters._
val a = Option("example").toJava // Creates java.util.Optional[String] containing "example"val b = (None: Option[String]).toJava // Creates an empty java.util.Optional[String]val c = a.toScala // Back to Option("example")val d = b.toScala // Back to None typed as Option[String]
This object provides extension methods that convert between Scala
Option
and JavaOptional
types.It differs from the JVM version as in it does not provide any conversions for the Optional primitive type wrappers which are available in the JDK but not in Scala-JS or Scala-Native.
Scala
Option
is extended with atoJava
method that creates a correspondingOptional
.Java
Optional
is extended with atoScala
method.Example usage: