Java Optional, NullPointerException Killer? Part 2

Опубликовано: 05 Ноябрь 2024
на канале: MVP Java
1,030
44

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 ...
   • Java Optional, NullPointerException K...  

The Source code is available onGitHub at https://github.com/mvpjava/java-optio...

I've also written a blog post ..
"Optional, NullPointerException Killer?"
which covers other aspects on the Java Optional Class.
Check it out here ...
http://mvpjava.com/java-optional/

======================================================
Follow me ...
Website: http://www.mvpjava.com
Facebook:   / mvpjava  
Twitter :   / mvpjava  
GitHub : https://github.com/mvpjava

Subscribe to MVP Java ...
https://www.youtube.com/c/MVPJava?sub...