Java 8 introduces Optional to deal with NPE. In practical application,I can‘t understand a problem.
I have the method A
public void doSomethingA(String para) {
Optional<String> name = Optional.of(para);
if (name.isPresent()) {
//do
}
}
But if para = null, it will throw NPE.
method B
public void doSomethingB(String para) {
if (para != null) {
//do
}
}
if I check para is not null, What's the difference between A and B.
Where is the meaning of Optional.