Handling Null: Optional and Nullable Types

Java has long been infamous for its NullPointerException. The reason for the NPE is calling a method or accessing an attribute of an object that has not been initialized.

Java
 
var value = foo.getBar().getBaz().toLowerCase();

Running this snippet may result in something like the following: