Skip to main content

Posts

Showing posts from February, 2022

Schema কি? (What is schema?)

Java 9 Optional Class Improvements

Optional class is introduced in Java 8 to prevent the null checks and NullPointerException. Before Java 8, if-constructs are used to check the null values. But, it is not an perfect way to check for null value as it doesn’t resolve NullPointerException although it just hides it and propagates it to the next level. Therefore, inspired by other functional programming languages, Optional class is introduced in Java to handle the null values from Java 8. Java 9 Optional Class Improvements : of() ,  empty() ,  ofNullable() ,  get() ,  ifPresent() ,  isPresent() ,  orElse() ,  orElseGet() ,  orElseThrow() ,  map() ,  flatMap()  and  filter()  are the methods of Java 8  Optional  class. Three more methods are added to  Optional  class from Java 9.  three new methods are added to improve its functionality. stream() ifPresentOrElse() or()  Let’s see these methods in detail. ifPresentOrElse() Method : This method performs the given action if the value is present in the  Optional  object.