A container object which may or may not contain an
int
value. If a value is present,
isPresent()
returns
true
and
getAsInt()
returns the value.
Additional methods that depend on the presence or absence of a contained value are provided, such as orElse()
(returns a default value if no value is present) and ifPresent()
(performs an action if a value is present).
This is a value-based class; use of identity-sensitive operations (including reference equality (==
), identity hash code, or synchronization) on instances of OptionalInt
may have unpredictable results and should be avoided.