object OptionConverters
This object provides extension methods that convert between Scala Option
and Java Optional
types.
Scala Option
is extended with a toJava
method that creates a corresponding Optional
, and
a toJavaPrimitive
method that creates a specialized variant (e.g., OptionalInt
) if
applicable.
Java Optional
is extended with a toScala
method and a toJavaPrimitive
method.
Finally, specialized Optional
types are extended with toScala
and toJavaGeneric
methods.
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] val e = Option(2.7).toJava // java.util.Optional[Double] containing boxed 2.7 val f = Option(2.7).toJavaPrimitive // java.util.OptionalDouble containing 2.7 (not boxed) val g = f.toScala // Back to Option(2.7) val h = f.toJavaGeneric // Same as e val i = e.toJavaPrimitive // Same as f
- Alphabetic
- By Inheritance
- OptionConverters
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
implicit final
class
RichOption[A] extends AnyVal
Provides conversions from Scala
Option
to JavaOptional
types -
implicit final
class
RichOptional[A] extends AnyVal
Provides conversions from Java
Optional
to ScalaOption
and specializedOptional
types -
implicit final
class
RichOptionalDouble extends AnyVal
Provides conversions from
OptionalDouble
to ScalaOption
and the genericOptional
-
implicit final
class
RichOptionalInt extends AnyVal
Provides conversions from
OptionalInt
to ScalaOption
and the genericOptional
-
implicit final
class
RichOptionalLong extends AnyVal
Provides conversions from
OptionalLong
to ScalaOption
and the genericOptional
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()