T - The type that may is present or notpublic final class Optional<T> extends Object
null value or not.
This class is designed after the java.util.Optional class of Java 8 and intended to be replaced with it when Java 7 support is dropped.
| Modifier and Type | Method and Description |
|---|---|
static <T> Optional<T> |
empty()
Creates an
Optional that has no value. |
T |
get()
The value of this
Optional. |
boolean |
isPresent()
Checks if this optional has a value or not.
|
static <T> Optional<T> |
of(T value)
Creates an
Optional that wraps a given non-null value. |
static <T> Optional<T> |
ofNullable(T value)
Creates an
Optional that wraps a given non-null value or null. |
public boolean isPresent()
true if it has, false if not.public T get() throws NoSuchElementException
Optional.NoSuchElementException - if this Optional has no value.public static <T> Optional<T> of(T value) throws NullPointerException
Optional that wraps a given non-null value.T - The type of the wrapped value.value - The value to wrap.NullPointerException - if the passed value was null.Copyright © 2015 Saxonia Systems AG. All Rights Reserved.