Object

scala.jdk

OptionConverters

Related Doc: package jdk

Permalink

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
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. OptionConverters
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. implicit final class RichOption[A] extends AnyVal

    Permalink

    Provides conversions from Scala Option to Java Optional types

  2. implicit final class RichOptional[A] extends AnyVal

    Permalink

    Provides conversions from Java Optional to Scala Option and specialized Optional types

  3. implicit final class RichOptionalDouble extends AnyVal

    Permalink

    Provides conversions from OptionalDouble to Scala Option and the generic Optional

  4. implicit final class RichOptionalInt extends AnyVal

    Permalink

    Provides conversions from OptionalInt to Scala Option and the generic Optional

  5. implicit final class RichOptionalLong extends AnyVal

    Permalink

    Provides conversions from OptionalLong to Scala Option and the generic Optional

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  14. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  16. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  17. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped