T
- The type of the value contained in this Optional
public interface Optional<T>
A container which may or may not contain a value. It is used for wrapping the return value of getter methods, where the return value might not be available.
If a value is present (available), theisPresent()
method will return true
and the value can be
retrieved using the get()
method.Modifier and Type | Method and Description |
---|---|
T |
get()
Gets the value held by this
Optional , if a value is present. |
boolean |
isPresent()
Checks if a value is present in this
Optional . |
boolean isPresent()
Optional
. Always use this method to determine, if the Optional
holds a value, before accessing it using the get()
method.true
if there is a value present, otherwise false
T get()
Optional
, if a value is present. Always call the isPresent()
method
to verify, that a value is available, before calling this method.T
) held by this Optional
NoSuchElementException
- if there is no value present in this Optional
Copyright © 2020. All rights reserved.