Generics - Eclipse compiler issues a warning, javac gives an error
<p>Assuming I have the following classes in an application:</p>

<p>A base class:</p>

<pre><code>public abstract class Animal {}
</code></pre>

<p>A subclass</p>

<pre><code>public class Dog extends Animal {

public void bark() {
    System.out.println("woof");
}
}
</code></pre>

<p>A class from a third party library:</p>

<pre><code>public class ThirdPartyLibrary /* *cough* Hibernate *cough* */{
public List find() {
    return new ArrayList() {
        // fetched from the db in the actual app of course
        {
            add(new Dog());
            add(new Dog());
            add(new Dog());
        }
    };
}
}
</code></pre>

<p>And a utility class:</p>

<pre><code>public class Util {

public &lt;E extends Animal&gt; E findUnique(List&lt;E&gt; animals) {
    return animals.isEmpty() ? null : animals.get(0);
}

/**
 * @param args
 */
public static void main(String[] args) {
    Dog d = new Util().findUnique(new ThirdPartyLibrary().find());
    d.bark();
}   
}
</code></pre>

<p>The eclipse compiler issues the following warnings:</p>

<blockquote>
  <ul>
  <li>Type safety: The expression of type List needs unchecked conversion to conform to List</li>
  <li>Type safety: Unchecked invocation findUnique(List) of the generic method findUnique(List) of type 
   Util</li>
  </ul>
</blockquote>

<p>But the build fails when compiling with Sun's javac with the error:</p>

<pre><code> incompatible types
    [javac] found   : Animal
    [javac] required: Dog
    [javac] Dog d = new Util().findUnique(new ThirdPartyLibrary().find());
    [javac]                          ^
</code></pre>

<p>Is there something else I can do to make this code compile in javac, apart from an explicit cast to <code>(List&lt;Dog&gt;)</code> before the call to findUnique?</p>
