title: simple generic list in java
body: <p>Why are java generics so tricky?  I thought I finally understood, but eclipse gives me an error at the line in somOtherMethod below using either of the getOuterList methods below.  </p>
  
  <pre><code>protected List&lt;?&gt; getOuterList() {
    // blah blah
  }
  
  protected List&lt;? extends Object&gt; getOuterList() {
    // blah blah
  }
  
  protected void someOtherMethod() {
    ...
    getOuterList().add((MyObject)myObject);  //compile error
    ...
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>: ok - so I understand the error now.  It was lack of understanding on my part of what <code>List&lt;?&gt;</code> or <code>List&lt;? extends SomeObject&gt;</code> really means.  In the former case, I thought it meant a list that could contain anything.  In the latter case, I assumed it was a list of a bunch of objects that extend SomeObject.  The proper representation of my understanding would just be <code>List&lt;Object&gt;</code> and <code>List&lt;SomeObject&gt;</code> (w/out the extends).  I thought extends helped me solve a problem which they don't.  So here's where my real problem lies:</p>
  
  <pre><code>public interface DogKennel {
    public List&lt;Dog&gt; getDogs();
  }
  
  public class GreyHoundKennel implements DogKennel {
  
    protected List&lt;GreyHound&gt; greyHounds;
  
    public List&lt;GreyHound&gt; getGreyHounds() {
      return this.greyHounds;
    }
  
    public List&lt;Dog&gt; getDogs() {
      // Is there no way to handle this with generics
      // w/out creating a new List?
      return getGreyHounds(); //compiler error
    }
  
  }
  </code></pre>