Module java.base
Package java.util

Class OptionalLong

java.lang.Object
java.util.OptionalLong

public final class OptionalLong extends Object
A container object which may or may not contain a long value. If a value is present, isPresent() returns true. If no value is present, the object is considered empty and isPresent() returns false.

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; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail.

API Note:
OptionalLong is primarily intended for use as a method return type where there is a clear need to represent "no result." A variable whose type is OptionalLong should never itself be null; it should always point to an OptionalLong instance.
Since:
1.8