What’s the benefit against using stubs?
Jorge Aguilar

Hi, Jorge Aguilar yes it would work same way and you would also avoid Nullability. But having Optionals always remind you to handle object’s absence case more wisely. 
ApiService was very trivial example I gave, In real life scenarios stubbing may not be good-idea/possible if:
1) Class you are dealing with, is a final class with no interface above it which you could stub.
2) Sometimes you also perform business/flow decisions based on inputs. 
If you have Stubs, you need to add extra logic to check if its a real object or a stub to perform same decision. With Optionals that comes for free with isPresent() method.

In general I feel Using Optionals over Stubs should be a standard pattern to use, across all the use-cases including above.

Like what you read? Give Biraj Patel a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.