I am writing this blog for demonstrating the usage of Optional class in java8, with nested objects.
Consider below the class structure,
Now consider that, you want to extract an email from the Employee object, also you have to avoid null pointer exception. In a traditional way, you have to write a lot of NULL conditions.
Check below code with an Optional class which simplifies your code structure.
I will write a few more posts for using an Optional with collection classes.
Consider below the class structure,
Now consider that, you want to extract an email from the Employee object, also you have to avoid null pointer exception. In a traditional way, you have to write a lot of NULL conditions.
Check below code with an Optional class which simplifies your code structure.
I will write a few more posts for using an Optional with collection classes.
No comments:
Post a Comment