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
If you don’t mind an answer without code, just my 0.02$.
We have been fighting over this at my work place (in code reviews) quite a lot. To be frank I am sometimes lost as to when it is correct (read intended by the creators of it) or not. I don’t even think that at the time of creation, Stuart Marks and the others were sure how this would be (ab)used. Like any other feature in the Java language, it will get abused, be sure of that. But over time, best practices will appear and people will use that.
I tend to be on the side that iff it does not hurt performance, your usage is OK. At least its sooo easy to read (speaking for myself here), compared to if else checks; but again it might be me doing (too) much Java-8 and above code.
That being said, it’s way too easy to turn it into a total mess, where that bound is, is up to you (and most probably your team).