Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why duplicated implements [duplicate]

As shown in java.util.*, AbstractSet<E> implements Set<E>, so why HashSet<E> extends AbstractSet<E> implements Set<E>? Is the "implements Set<E>" duplicated here?

like image 527
Tai Zhou Avatar asked Oct 02 '22 04:10

Tai Zhou


2 Answers

This has been done to be able to override the javadoc documentation.
The javadoc for HashSet<E> and AbstractSet<E> differ for example.

It can also be done for more clarity.

like image 125
skiwi Avatar answered Oct 18 '22 04:10

skiwi


Yes it is duplicated, but I guess it is a coding style decision. I as well do prefer to explicitly implement the interfaces a type is motivated to be introduced for. The extends is just an implementation detail, most often motivated by reuse. Hence, the type which inherits from the base class will be stable even when removing the base class and implementing those functionality in some other way.

like image 39
Harmlezz Avatar answered Oct 18 '22 02:10

Harmlezz