4.3.  Describe the unique characteristics of the Optional class

[Note]

A java.util.Optional<T> object is either a wrapper for an Object of type T or a wrapper for no object. It is intended as a safer alternative than a reference of type T that refers to an Object or null.

Following is the declaration for java.util.Optional<T> class:


public final class Optional<T> extends Object {
    ...
}

					

Creating Optional objects

The first step before working with Optional is to learn how to create optional objects. There are several ways:

Unwrapping an Optional

The Optional class provides several instance methods to read the value contained by an Optional instance.

Professional hosting         Free 'Oracle Certified Expert Web Services Developer 6' Guide     Exam 1Z0-810: Upgrade to Java SE 8 Programmer Quiz