When scrolling through the documentation for the java.util package, I was surpised to find that Optional<T>
and OptionalInt
have no relationship to each other. This seems very hard to belive, as it suggests that they are unrelated classes.
- Why don't they have a common interface, class, are sub-types, or something to reveal the relationship they have? (They're very similar classes when you look at their uses.)
- Also, why the need for an additional
OptionalInt
class? Why can't you just useOptional<Integer>
? I thought it was due to the fact thatint
is primitive, but there is noOptionalChar
so that would be an inconsistent design choice.