To my understanding following code should not throw Null Pointer exception
as I am safely using Optional interface.
However, when I ran this code it is throwing NPE
.
public class Test {
public static void main(String[] args) {
final Integer inte = false ? 0 : Optional.ofNullable((Integer) null).orElse(null);
}
}
Please let me know if I am mistaken somewhere in my code and help me to rectify the same.