Optional in Java
Optional : In order to get rid of NullPointerException. Java8 introduced a new class in the java.util.Optional It is a container object , which value may or may not contain null value. It is a value based class , use of ==, identity hash code, synchronisation, may give unpredictable results and avoided. It is type safe way of dealing with values which might be null. It is elegant way of dealing with nulls in functional code. How we can prevent these null checks? To indicate that a method can return an actual value or null value, we can wrap the returned object in an Optional. It deals with null value at compile time level rather than at run time level. Runtime exceptions discovered in production become compile time concerns during development. It contains some useful methods as below: public static <T> Optional<T> of (T value) ——> it can throw null pointer exception if value is null public static <T> Optional<T> ofNullable (T value)—>...