Is it good idea to use Optional.of() method to make method chaining ?
i had a conversation with group of collegues about Optional.of() method. currently one of the
I think, Java Optional is made for these type of use cases only - To avoid null checks and do operations via chaining & without the fear of NPE.
I don't think you are overusing Optional.
From the Official Article from Oracle
The purpose of Optional is not to replace every single null reference in your codebase but rather to help design better APIs in which—just by reading the signature of a method—users can tell whether to expect an optional value. In addition, Optional forces you to actively unwrap an Optional to deal with the absence of a value; as a result, you protect your code against unintended null pointer exceptions.