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
- Alphabetic
- By Inheritance
- Optional
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
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(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(obj: AnyRef): Boolean
- Definition Classes
- Optional → AnyRef → Any
- Annotations
- @Override()
- def get(): T
- returns
the value wrapped by this
Optional
- Exceptions thrown
NullPointerException
if this is empty (contains no value)
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- def hashCode(): Int
- Definition Classes
- Optional → AnyRef → Any
- Annotations
- @Override()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isPresent(): Boolean
- returns
true iff this
Optional
contains a value (non-empty)
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- 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
- 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
- def orNull(): T
- returns
this
Optional
's value if present, or else null
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- Optional → AnyRef → Any
- Annotations
- @Override()
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)