You must use Optional only if you will throw an exception when is empty.
By instance if you have a repo that find an object based on a specification, and a use case that call that repo, if the optional is empty the use case must throw an exception or return an error but never return that empty optional.
View all comments
-2
u/Dense_Age_1795 Sep 28 '26
You must use Optional only if you will throw an exception when is empty.
By instance if you have a repo that find an object based on a specification, and a use case that call that repo, if the optional is empty the use case must throw an exception or return an error but never return that empty optional.