#java8 What is Optional class in java 8 ? Why Optional class is introduced in java 8 ? | #java

preview_player
Показать описание
Hello All,

In todays interview we have seen
what is Optional class ?

The Optional is a wrapper class that makes a field optional which means it may or may not have values. It improves the readability .
By using Optional, you can specify alternative values to return when something is null.
EX. if you have an Employee Object and it has yet to assign a department, instead of returning null, you can return a default department. Earlier, there was no option to specify such default value in Java code but from Java 8 onwards, Optional can be used for that.

How to create Optional ?

Important methods of Optional Class

get()
isPresent()
orElse()
orElseThrows()

Java Interview questions on java8 new features
java8 new features
Lambda expressions and Functional Interface
Default Methods in java8

Thank you for watching the video please share with your friends and Subscribe to the channle.
Рекомендации по теме