What’s the difference between
get() of the
Both of them wait for the future completion.
The only difference is what kind of exceptions these two methods throw.
get(), originated in the
Future interface, throws “checked exceptions”.
join() throws “unchecked exceptions”.
In old days, like Java 1.5 era when
Future.get() was designed, checked exceptions might be preferred.
Nowadays, unchecked exceptions are more preferred, therefore
join() is preferred.
As per Javadoc of CompletableFuture,
To simplify usage in most contexts, this class also defines methods join() and getNow(T) that instead throw the CompletionException directly in these cases.
In other words,
join() is simpler to use, in the sense of exception handling.
It’s kind of an official recommendation.