title: Why do I get "Illegal generic type for instanceof"?
body: <p>Given:</p>
  
  <pre><code>public class C&lt;T&gt; {
      private class D {
          public boolean equals( Object o ) {
              if ( !(o instanceof D) )    // line 4
                  return false;
              D other = (D)o;             // line 6
              return i == other.i;
          }
          int i;
      }
  }
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>C.java:4: illegal generic type for instanceof
            if ( !(o instanceof D) )
                                ^
  </code></pre>
  
  <p>I also get an "unchecked cast" warning about line 6.  Why?  The <code>o</code> is <em>not</em> a generic type -- it's just a plain <code>Object</code>.  How can I correctly implement <code>equals()</code> by both checking for and casting to an instance of <code>D</code>?</p>
  
  <p>Note: Obviously, this code example is a whittled-down version of my actual code.  The real classes for <code>C</code> and <code>D</code> are much larger and <code>D</code> is a <code>private</code> inner class of <code>C</code> used by its implementation.</p>
  
  <p>FYI: The real <code>D</code> does make use of the generic parameter <code>T</code>.</p>