title: Java: Set interface and Collection interface differences
body: <p>I just looked up the <code>Set</code> interface and found that it mostly (or completely) only redeclares functions which are already in the <code>Collection</code> interface. <code>Set</code> itself extends <code>Collection</code>, so doesn't that mean that the <code>Set</code> interface automatically has all the functions from <code>Collection</code>? So why are they redeclared then?</p>
  
  <p>For example, <code>Set</code> redeclares this:</p>
  
  <pre><code>/**
   * Returns the number of elements in this set (its cardinality).  If this
   * set contains more than &lt;tt&gt;Integer.MAX_VALUE&lt;/tt&gt; elements, returns
   * &lt;tt&gt;Integer.MAX_VALUE&lt;/tt&gt;.
   *
   * @return the number of elements in this set (its cardinality)
   */
  int size();
  
  /**
   * Returns &lt;tt&gt;true&lt;/tt&gt; if this set contains no elements.
   *
   * @return &lt;tt&gt;true&lt;/tt&gt; if this set contains no elements
   */
  boolean isEmpty();
  </code></pre>
  
  <p>And the declaration in <code>Collection</code>:</p>
  
  <pre><code>/**
   * Returns the number of elements in this collection.  If this collection
   * contains more than &lt;tt&gt;Integer.MAX_VALUE&lt;/tt&gt; elements, returns
   * &lt;tt&gt;Integer.MAX_VALUE&lt;/tt&gt;.
   *
   * @return the number of elements in this collection
   */
  int size();
  
  /**
   * Returns &lt;tt&gt;true&lt;/tt&gt; if this collection contains no elements.
   *
   * @return &lt;tt&gt;true&lt;/tt&gt; if this collection contains no elements
   */
  boolean isEmpty();
  </code></pre>
  
  <p>This seems very redundant to me. Why not just define the <code>Set</code> interface as:</p>
  
  <pre><code>public interface Set&lt;E&gt; extends Collection&lt;E&gt; {}
  </code></pre>
  
  <p>I think there is no single difference between those interfaces, right?</p>
  
  <hr>
  
  <p>Of course I am not asking about the different semantics / meaning of <code>Set</code>. I know that. I am just asking about if it technically (i.e. to the compiler) has any difference. I.e., speaking generally:</p>
  
  <pre><code>interface A { void foo(); }
  interface B extends A { void foo(); }
  interface C extends A {}
  </code></pre>
  
  <p>Now, is there any difference between <code>A</code>, <code>B</code> or <code>C</code>?</p>
  
  <hr>
  
  <p>While the contract (i.e. what is said in the documentation) can really be different for some functions (as for <code>add</code>), there is a valid reason to redeclare them: To be able to put a new documentation, i.e. to define the new contract.</p>
  
  <p>However, there are also functions (like <code>isEmpty</code>) which have exactly the same documentation / contract. Why are they also redeclared?</p>