T
- Type of the valuepublic final 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.
|
Object |
orNull()
Returns the wrapped value, if present, otherwise
null . |
public static <T> Optional<T> empty()
T
- Type of the non-existent valuepublic static <T> Optional<T> of(T value)
T
- the class of the valuevalue
- the value to be present, which must be non-nullpublic static <T> Optional<T> ofNullable(T value)
T
- the class of the valuevalue
- the possibly-null value to describepublic boolean isPresent()
public T get()
isPresent()
public Object orNull()
null
.null
Copyright © 2018. All rights reserved.