2 ms·
That's not really "why" it was introduced. Optional is used as a null wrapper in other JVM languages so that idiom bled over pretty naturally. Here's a talk "O
by kjeetgill 7y ago
That's not really "why" it was introduced. Optional is used as a null wrapper in other JVM languages so that idiom bled over pretty naturally.
Here's a talk "Optional - Mother of all Bikesheds" by Stuart Marks, the guy who added it to OpenJDK: https://m.youtube.com/watch?v=Ej0sss6cq14 https://m.youtube.com/watch?v=Ej0sss6cq14
It was mostly just meant to cover the zero or one case on fluent-style interfaces like the Streams API, so check as getFirst() or getAny(). In hindsight, the name Optional was a poor choice if they didn't want the idiom coming over.