Null check vs Optional isPresent check
<p>Can someone explain how <code>Optional</code> helps us avoid <code>NullPointerException</code>?</p>

<pre><code>Optional&lt;String&gt; op = someFunc()
if(op.isPresent()) {
   op.get();
}
String possibleNull = op.get();
</code></pre>

<p>Isn't this code prone to <code>NullPointerException</code> too? If so, then why is this code preferred over</p>

<pre><code>String op = someFunc()
if(op != null) {
   op.get();
}
String possibleNull = op;
</code></pre>

<p>What possible benefit does <code>Optional</code> provide other than the fact that it helps us in knowing whether a function actually had a return value or not</p>