public abstract class Option<T>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Option.None<T>
The None type, representing an absent value (instead of "null")
|
static class |
Option.Some<T>
The Some type, representing an existence of some value
|
Constructor and Description |
---|
Option() |
Modifier and Type | Method and Description |
---|---|
static <T> Option<T> |
fromNullable(T value)
Wraps value in an Option type, depending on whether or not value is null
|
abstract T |
get()
Get the value of the Option (if it is defined)
|
abstract boolean |
isDefined()
Whether the Option is defined or not
|
static <T> Option.None<T> |
none() |
T |
or(T other)
Get the contained value (if defined) or else return a default value
|
static <T> Option.Some<T> |
some(T value)
Wrap value in a Some type (NB! value must not be null!)
|
public abstract boolean isDefined()
public abstract T get()
java.lang.IllegalStateException
- if called on a Nonepublic T or(T other)
other
- what to return if the value is not defined (a None)public static <T> Option<T> fromNullable(T value)
T
- type of valuevalue
- public static <T> Option.Some<T> some(T value)
T
- type of valuevalue
- public static <T> Option.None<T> none()