I just looked up the Set
interface and found that it mostly (or completely) only redeclares functions which are already in the Collection
interface.
They are redeclared because, even if the names are same, they have different meaning. The add
method in the Set
is a specific implementation of the generic add
method in Collection
.
The intention is to explicitly specify that the add
method os the Set
is very different from the add method of Collection
.
Why not just define the Set interface as:
public interface Set extends Collection {}
If it has been done this way, there would be no place where the contract of a Set
can be specified. How would I know that by implementing the add
method of the Set
, I should not allow duplicates?