T
- the expected type of the nullable value.public class Optional<T>
extends java.lang.Object
Constructor and Description |
---|
Optional(T value)
Constructs a new optional value
|
Modifier and Type | Method and Description |
---|---|
static <T> Optional<T> |
empty()
Returns an empty Optional instance.
|
boolean |
equals(java.lang.Object rhs) |
static <T> Optional<T> |
from(T value) |
T |
get()
Gets the optional value if present.
|
int |
hashCode() |
boolean |
isPresent()
Checks if a non-null value is present.
|
public Optional(@Nullable T value)
value
- the optional valuepublic static <T> Optional<T> from(T value)
public boolean isPresent()
@NonNull public T get()
java.util.NoSuchElementException
- if the value is null.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object rhs)
equals
in class java.lang.Object
public static <T> Optional<T> empty()
T
- Type of the optional value