title: How to cast generic List types in java?
body: <p>Well, I have a class Customer (no base class).</p>
  
  <p>I need to cast from LinkedList to List. Is there any clean way to do this?</p>
  
  <p>Just so you know, I need to cast it to List. No other type will do. (I'm developing a test fixture using Slim and FitNesse).</p>
  
  <hr>
  
  <p>EDIT: Okay, I think I need to give code examples here.</p>
  
  <pre><code>import java.util.*;
  public class CustomerCollection
  {
      protected LinkedList&lt;Customer&gt; theList;
  
      public CustomerCollection()
      {
          theList = new LinkedList&lt;Customer&gt;();
      }
  
      public void addCustomer(Customer c){ theList.add(c); }
      public List&lt;Object&gt; getList()
      {
          return (List&lt;? extends Object&gt;) theList;
      }
  }
  </code></pre>
  
  <p>So in accordance with Yuval A's remarks, I've finally written the code this way. But I get this error:</p>
  
  <pre><code>CustomerCollection.java:31: incompatible types
  found   : java.util.List&lt;capture#824 of ? extends java.lang.Object&gt;
  required: java.util.List&lt;java.lang.Object&gt;
          return (List&lt;? extends Object&gt;)theList;
                 ^
  1 error
  </code></pre>
  
  <p>So, what's the correct way to do this cast?</p>