KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I just looked up the Set interface and found that it mostly (or completely) only redeclares functions which are already in the Collection interface. Set itself extends Collection , so doesn't that mean that the Set interface automatically has all the functions from Collection ? So why are they redeclared then? For example, Set redeclares this: /** * Returns the number of elements in this set (its cardinality). If this * set contains more than <tt>Integer.MAX_VALUE</tt> elements, returns * <tt>Integer.MAX_VALUE</tt>. * * @return the number of elements in this set (its cardinality) */ int size(); /** * Returns <tt>true</tt> if this set contains no elements. * * @return <tt>true</tt> if this set contains no elements */ boolean isEmpty(); And the declaration in Collection : /** * Returns the number of elements in this collection. If this collection * contains more than <tt>Integer.MAX_VALUE</tt> elements, returns * <tt>Integer.MAX_VALUE</tt>. * * @return the number of elements in this collection */ int size(); /** * Returns <tt>true</tt> if this collection contains no elements. * * @return <tt>true</tt> if this collection contains no elements */ boolean isEmpty(); This seems very redundant to me. Why not just define the Set interface as: public interface Set<E> extends Collection<E> {} I think there is no single difference between those interfaces, right? Of course I am not asking about the different semantics / meaning of Set . I know that. I am just asking about if it technically (i.e. to the compiler) has any difference. I.e., speaking generally: interface A { void foo(); }
Tags (comma-separated)
Save Edits
Cancel