Java 8 Optional Null Check
<p>I am trying to check if the input is null then output should be null
Or if the input is String, then it should convert it to Long</p>

<p>Assuming input is never "abcd", input is either null or "12", "14", etc.</p>

<p>The following code snippet throws null pointer exception, as I am not able to use Java 8 Optional properly. I can catch the null pointer exception or use if/else with tertiary'?' operator but Is there any way to handle this scenario with Optional?</p>

<pre><code>public class OptionalClass {

public void methodA(String input) {
    System.out.println(Long.valueOf(Optional.ofNullable(input).orElse(null)));
}

public static void main(String[] args) {
    new OptionalClass().methodA("12");// This works fine
    new OptionalClass().methodA(null); // This throws null pointer exception
}   }
</code></pre>