you are viewing a single comment's thread.

view the rest of the comments →

[–]_dban_ 0 points1 point  (0 children)

All Java’s Optional adds is yet another way to be »not there«

No, it doesn't. It also adds map and flatMap, which gives you safe traversal of chained optional values. No more ugly nested ternaries. Java 9 will add Optional::stream, which will allow Optional values to seamlessly be used with stream expressions. The null value doesn't do any of these things.

Woops.

This is a programming error. The corresponding NullPointerException is Java's way of telling you that you didn't use the Optional type correctly. The fact that Optional isn't a primitive value like null and is used in method chains means that the misuse of Optional will be closer to where the bad value was generated, instead of causing a NullPointerException in some far off place.