Java Optional, NullPointerException Killer? Part 2

preview_player
Показать описание
The Java Optional class was introduced in Java 8 in order to help stop the propagation of null being returned to client facing methods.

The problem is that everyone started using it everywhere they say null. This caused confusion, un-necessary overhead and left everyone scratching their heads.

Does the Java Optional Class finally rid us of NullPointerExceptions? I’ll demonstrate how when Optional is used correctly and when combined with Java’s functional style of programming, that this is indeed possible.

In this tutorial (Part 2) we'll look at a more functional style of programming in dealing with Java Optional in terms of ...

- How to handle a returned Java Optional to extract its value
- How to return an Optional
- How to return an Optional value

You'll learn Optional methods or, orElse, orElseGet, orElseThrow, stream
and know how to handle a List of Optionals with stream methods filter, map and flatMap

If you missed Part 1 - "Java Optional, NullPointerException Killer? Part 1" Then click here ...

I've also written a blog post ..
"Optional, NullPointerException Killer?"
which covers other aspects on the Java Optional Class.
Check it out here ...

======================================================
Follow me ...

Subscribe to MVP Java ...
Рекомендации по теме
Комментарии
Автор

Dang dude. I feel you explained flatMap() better than Stuart Marks did in his bikeshedding presentation about Optional, which is 45 minutes to an hour depending on which time he presented it. I liked his presentation too, but for many watching your two videos would probably make more sense. I do feel there was more time spent on the functional/stream cases in his, whereas here it is almost an afterthought. My sense from watching his presentation was that it was sometimes nice for API designers outside of Streams, but like, totally essential when working with Streams. There's less emphasis here on that, but nothing undid that impression for me either.

jvsnyc