Tag: optional

  • The best way to use Optional in Java

    Null pointer exceptions. They have often been a headache to java developers. Your application breaks out of nowhere and throws null pointer exceptions. You rub your forehead then and add that null check you missed out. Java wanted to solve this problem. And they introduced the Optional keyword. They described it as a “Container” that…

  • How to use Optional keyword to avoid NullPointerException in nested objects in Java?

    Let’s say you have a nested object in your application . And you want to retrieve the value of a field in the deepest nested object. We will see how to do this using pre-Java 8 and post-Java 8 code (using Optional keyword) Lets consider an Employee object, Let’s say the Employee object has an…