Packages

final class Optional[T] extends Serializable

Like java.util.Optional in Java 8, scala.Option in Scala, and com.google.common.base.Optional in Google Guava, this class represents a value of a given type that may or may not exist. It is used in methods that wish to optionally return a value, in preference to returning null.

In fact, the class here is a reimplementation of the essential API of both java.util.Optional and com.google.common.base.Optional. From java.util.Optional, it implements:

  • #empty()
  • #of(Object)
  • #ofNullable(Object)
  • #get()
  • #orElse(Object)
  • #isPresent()

From com.google.common.base.Optional it implements:

  • #absent()
  • #of(Object)
  • #fromNullable(Object)
  • #get()
  • #or(Object)
  • #orNull()
  • #isPresent()

java.util.Optional itself was not used because at the time, the project did not require Java 8. Using com.google.common.base.Optional has in the past caused serious library version conflicts with Guava that can't be resolved by shading. Hence this work-alike clone.

Source
Optional.java
Linear Supertypes
Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Optional
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(obj: AnyRef): Boolean
    Definition Classes
    Optional → AnyRef → Any
    Annotations
    @Override()
  8. def get(): T

    returns

    the value wrapped by this Optional

    Exceptions thrown

    NullPointerException if this is empty (contains no value)

  9. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  10. def hashCode(): Int
    Definition Classes
    Optional → AnyRef → Any
    Annotations
    @Override()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. def isPresent(): Boolean

    returns

    true iff this Optional contains a value (non-empty)

  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  16. def or(other: T): T

    other

    value to return if this is empty

    returns

    this Optional's value if present, or else the given value

  17. def orElse(other: T): T

    other

    value to return if this is empty

    returns

    this Optional's value if present, or else the given value

  18. def orNull(): T

    returns

    this Optional's value if present, or else null

  19. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  20. def toString(): String
    Definition Classes
    Optional → AnyRef → Any
    Annotations
    @Override()
  21. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  22. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  23. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped