T
- Type for optionalpublic class Optional<T> extends Object
Modifier and Type | Method and Description |
---|---|
static <T> Optional<T> |
empty()
Returns an empty Optional instance.
|
T |
get()
If a value is present in this Optional, returns the value, otherwise throws NoSuchElementException.
|
boolean |
isPresent()
Return true if there is a value present, otherwise false.
|
static <T> Optional<T> |
of(T value)
Returns an Optional with the specified present non-null value.
|
static <T> Optional<T> |
ofNullable(T value)
Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional.
|
T |
orElse(T other)
Return the value if present, otherwise return other.
|
String |
toString() |
public static <T> Optional<T> empty()
public static <T> Optional<T> of(@NonNull T value)
value
- the value to be present, which must be non-nullpublic static <T> Optional<T> ofNullable(T value)
value
- the possibly-null value to describepublic T get()
NoSuchElementException
- - if there is no value presentpublic boolean isPresent()
public T orElse(T other)
other
- the value to be returned if there is no value present, may be nullCopyright © 2020. All rights reserved.