I believe that, if done right, checked exceptions can benefit an API. However, they weren’t given the proper TLC in the new Java 8 APIs, particularly in the Streams. But if Java was enhanced with default generics, the mess could be cleaned up.
API Design
Use Optional to Shield Yourself from Bad API Design
There are many articles that explain the broad applications of Java 8’s new Optional
class (e.g., Tired of Null Pointer Exceptions? Consider Using Java SE 8’s Optional
!), but they focus on how authors can use Optional
to improve the design of their own APIs. I want to talk about how Optional
can be used to protect us from the APIs we didn’t write.