title: Is there a way to force the return type of Arrays.asList
body: <p>I have a method returning a collection of a base class:</p>
  
  <pre><code>import java.util.*;
  class Base { }
  class Derived extends Base { }
  
  Collection&lt;Base&gt; getCollection()
  {
      return Arrays.asList(new Derived(),
                           new Derived());
  }
  </code></pre>
  
  <p>This fails to compile, as the return type of <code>Arrays.asList</code> (<code>List&lt;Derived&gt;</code>) does not match the return type of the method (<code>Collection&lt;Base&gt;</code>).  I understand why that happens: since the generic types are different, the two classes are not related by inheritance.</p>
  
  <p>There are many ways to fix the compiler error from changing the return type of the method to not using Arrays.asList to casting one of the derived objects to Base.  </p>
  
  <p>Is there a way to tell the compiler to use a different but compatible type when it resolves the generic type for the Arrays.asList call?  (I keep trying to use this pattern and running into this problem, so if there is a way to make it work, I would like to know it.)</p>
  
  <p>I thought that you could do something like</p>
  
  <pre><code>Collection&lt;Base&gt; getCollection()
  {
      return Arrays.asList&lt;Base&gt;(new Derived(),
                                 new Derived());
  }
  </code></pre>
  
  <p>When I try to compile that (java 6), the compiler complains that it is expecting a ')' at the comma.  </p>