Using Optional Correctly to Handle Null Pointer (NPE) Exceptions Elegantly
To understand why Optional exists, you first need to understand NPE. Many object-oriented languages have a null value: a pointer on the stack that points at a heap address that doesn't exist. Use that object and you get a NullPointerException. If you fail to anticipate the null case, your program crashes.









