If non-null, the value; if null, indicates no value is present
Common instance for empty
.
If a value is present, apply the provided Optional
-bearing
mapping function to it, return that result, otherwise return an empty
Optional
. This method is similar to map
,
but the provided mapper is one whose result is already an Optional
,
and if invoked, flatMap
does not wrap it with an additional
Optional
.
The type parameter to the Optional
returned by
a mapping function to apply to the value, if present the mapping function
the result of applying an Optional
-bearing mapping
function to the value of this Optional
, if a value is present,
otherwise an empty Optional
If a value is present, invoke the specified consumer with the value, otherwise do nothing.
block to be executed if a value is present
If a value is not present, returns true
, otherwise
false
.
value true if a value is not present, otherwise false
If a value is present, apply the provided mapping function to it,
and if the result is non-null, return an Optional
describing the
result. Otherwise return an empty Optional
.
This method supports post-processing on optional values, without
the need to explicitly check for a return status.
For example, the following code creates Optional around a response,
and then checks is the received request successful.
const responseIsSuccessful = Optional.ofNullable(response) .map(resp => resp.isSuccessful) .orElse(false);
Here, Optional.ofNullable(response)
returns an Optional<any>
, and then
map
returns an Optional<boolean>
.
The type of the result of the mapping function
a mapping function to apply to the value, if present
an Optional
describing the result of applying a mapping
function to the value of this Optional
, if a value is present,
otherwise an empty Optional
Return the value if present, otherwise return other
.
the value to be returned if there is no value present, may be null
the value, if present, otherwise other
Return the value if present, otherwise invoke other
and return
the result of that invocation.
a {@linkcode Supplier} whose result is returned if no value is present
the value if present otherwise the result of other()
Return the contained value, if present, otherwise throw an error to be created by the provided supplier.
The supplier which will return the error to be thrown
the present value
Generated using TypeDoc
A container object which may or may not contain a non-null value. If a value is present,
isPresent
will returntrue
andget
will return the value.Additional methods that depend on the presence or absence of a contained value are provided, such as
orElse
(return a default value if value not present) andifPresent
(execute a block of code if the value is present).This is a value-based class.