title: Parameterised method returning generic class member in java
body: <p>Why is the following code not allowed?</p>
  
  <pre><code>class MyClass {
      List&lt;? extends Something&gt; list;
      &lt;T extends Something&gt; List&lt;T&gt; myFunc(T t) {
          list = new ArrayList&lt;T&gt;(); // ok
          list.add(t); // error
          return list; // error
      }
  }
  </code></pre>
  
  <p>And how do you fix the code while maintaining the same? i.e. the class member <code>list</code> only accepts objects that is subclass of <code>Something</code> and the same for <code>myFunc()</code>?</p>