This block of code creates an anonymous subclass of CompletableFuture
. This anonymous subclass overrides the cancel(bool)
method with a new implementation. An anonymous subclass is equivalent to creating a new class that extends CompleteableFuture
with the caveat that it isn't straightforward to re-use this new subclass somewhere else.
@Override
is not strictly necessary in this case but it provides you several benefits, as described by the answer to this question:
Use it every time you override a method for two benefits. Do it so that you can take advantage of the compiler checking to make sure you actually are overriding a method when you think you are. This way, if you make a common mistake of misspelling a method name or not correctly matching the parameters, you will be warned that you method does not actually override as you think it does. Secondly, it makes your code easier to understand because it is more obvious when methods are overwritten.
Additionally, in Java 1.6 you can use it to mark when a method implements an interface for the same benefits. I think it would be better to have a separate annotation (like @Implements), but it's better than nothing.