The class java.util.Optional
is implemented as a single immutable concrete class that internally handles two cases; one with an element and one without. Wouldn't it have been a better choice to let Optional
be an interface and have two different implementations implement that interface instead? After all, that is what we generally are taught to do in an object-oriented language.
In this article, we will learn about some of the potential arguments for the current Optional
implementation. We will also learn why Streams are implemented in a different way, enabling Streams to be obtained from files or even database tables.