Optional - The Mother of All Bikesheds by Stuart Marks
DevoxxCited 3× on HN, 2019–2022
talk · intermediate · evergreen · 2019–2022 on HN
Stuart Marks explains the intended purpose and proper use of Java 8's Optional class and why it caused so much controversy. He gives guidelines for using its small API correctly.
Cited as the authoritative explanation, from the person who added it to OpenJDK, of Optional's narrow intended purpose.
Up next
18 mo on HNRuby Conf 12 - Y Not- Adventures in Functional Programming by Jim Weirich
Confreaks
Recommended 17× on HN · 2013–2026
16 mo on HNThe spelled-out intro to neural networks and backpropagation: building micrograd
Andrej Karpathy
Recommended 17× on HN · 2022–2025
16 mo on HNHow Python was Shaped by leaky Internals, Armin Ronacher, Flask framework
Видео с мероприятий {speach!
Recommended 15× on HN · 2017–2025
15 mo on HNRailsConf 2014 - All the Little Things by Sandi Metz
Confreaks
Recommended 15× on HN · 2015–2025
14 mo on HNWhat the heck is the event loop anyway? | Philip Roberts | JSConf EU
JSConf
Recommended 16× on HN · 2015–2025
12 mo on HNHow To Design A Good API and Why it Matters
Google TechTalks
Recommended 12× on HN · 2011–2025
12 mo on HNThe Problem with Time & Timezones - Computerphile
Computerphile
Recommended 12× on HN · 2014–2026
10 mo on HNRailsConf 2016 - Turbolinks 5: I Can’t Believe It’s Not Native! by Sam Stephenson
Confreaks
Recommended 6× on HN · 2017–2020
9 mo on HNBrian Goetz - Stewardship: the Sobering Parts
ClojureTV
Recommended 10× on HN · 2014–2025
10 mo on HNRuby Midwest 2011 - Keynote: Architecture the Lost Years by Robert Martin
Confreaks
Recommended 10× on HN · 2013–2022
10 mo on HNJavaScript: The Good Parts
Google TechTalks
Recommended 11× on HN · 2009–2020
9 mo on HNUsing Python to Code by Voice
Next Day Video
Recommended 12× on HN · 2013–2025
3 comments from Hacker News
See also the discussion for a similar feature in Java, from "Optional: The Mother of all Bikesheds", where the use and misuse of get() has a central role. video: ▶ this video slides: link
These are pretty weak arguments For the first point - val/var "More importantly, it doesn’t offer its immutable counterpart, val. You still need to add the final keyword, which nearly nobody uses." This super undermines the criticism. "It has the feature but people don't use it" isn't exactly much to write home about. Just use `final var` if you want. Make "final var over var" the same force culturally as JS's const over let" "However, the developers of Optional designed it for return values only. Nothing is available in the language syntax for methods parameters and return values. To cope with this, a bunch of libraries provides compile-time annotations:" This flow of causality here is slightly incoherent. The phrasing implies that if there was a version of optional that was designed for method parameters that would be better and there would be less of a need for compile-time annotations. Here it is sealed interface Option<T> { record Some<T>(T value) implements Option<T> {} record None<T>() implements Option<T> {} } This has "better" semantics than Optional for storing in fields and for using as method parameters. The existence of this does not obviate the desire to have null static analysis, so Optional really isn't that related. ▶ this video It is true though that Kotlin has a more consistent story here, but there are active efforts to improve it for Java. Also, the discussion of extension functions points out that static methods cannot be chained like instance methods - corre
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: ▶ this video 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.