The concept of ``++Optional++`` is that it will be used when ``++null++`` could cause errors. In a way, it replaces ``++null++``, and when ``++Optional++`` is in use, there should never be a question of returning or receiving ``++null++`` from a call. == Noncompliant Code Example [source,java] ---- public void doSomething () { Optional optional = getOptional(); if (optional != null) { // Noncompliant // do something with optional... } Optional text = null; // Noncompliant, a variable whose type is Optional should never itself be null // ... } @Nullable // Noncompliant public Optional getOptional() { // ... return null; // Noncompliant } ---- == Compliant Solution [source,java] ---- public void doSomething () { Optional optional = getOptional(); optional.ifPresent( // do something with optional... ); Optional text = Optional.empty(); // ... } public Optional getOptional() { // ... return Optional.empty(); } ---- ifdef::env-github,rspecator-view[] ''' == Implementation Specification (visible only on this page) include::message.adoc[] endif::env-github,rspecator-view[]