Optionals are a language concept that have been introduced in Java 8.
A story of why optionals have been introduced can be found here
Optionals are represented by the Optional class in the java.util package and it is used to represent if a value is present or absent. The main advantage of this new construct is that it can avoid too many null checks and it avoids any runtime NullPointerExceptions. Optionals also support us in developing clean APIs, as they express intent that a value might be absent.
In today's exercises, the focus will be on:
- Syntax of Optionals
- What to do when an API returns an Optional
- Optionals and Streams
Documentation about Optionals can be found here