Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What is erased is <code>E</code>. You can't, in fact, do <code>if (e instanceof E)</code>, because the type parameter <code>E</code> is erased. However, <code>String</code> is not a parameterized type, and <code>e</code> does have a run-time type, so <code>if (e instanceof String)</code> works just fine.</p> <h3><a href="http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.20.2" rel="nofollow noreferrer">JLS 15.20.2 Type comparison <code>instanceof</code> operator</a></h3> <blockquote> <pre><code>RelationalExpression: RelationalExpression instanceof ReferenceType </code></pre> <p>The type of a <code>RelationalExpression</code> operand of the <code>instanceof</code> operator must be a reference type or the <code>null</code> type; otherwise, a compile-time error occurs. The <code>ReferenceType</code> mentioned after the <code>instanceof</code> operator must denote a reference type; otherwise, a compile-time error occurs. <strong>It is a compile-time error if the</strong> <code>ReferenceType</code> <strong>mentioned after the</strong> <code>instanceof</code> <strong>operator does not denote a reifiable type</strong> (§4.7).</p> </blockquote> <p><code>String</code> is a reifiable type. <code>E</code> is not.</p> <h3><a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.7" rel="nofollow noreferrer">JLS 4.7 Reifiable Types</a></h3> <blockquote> <p>Because some type information is erased during compilation, not all types are available at run time. Types that are completely available at run time are known as reifiable types. A type is reifiable if and only if one of the following holds:</p> <ul> <li>It refers to a non-generic type declaration.</li> <li>It is a parameterized type in which all type arguments are unbounded wildcards</li> <li>It is a raw type.</li> <li>It is a primitive type.</li> <li>It is an array type whose component type is reifiable.</li> </ul> </blockquote> <h3>See also</h3> <ul> <li><a href="https://stackoverflow.com/questions/1570073/java-instanceof-and-generics">Java: Instanceof and Generics</a></li> <li><a href="https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it">What is a raw type and why shouldn’t we use it?</a> <ul> <li><code>instanceof</code> and <code>.class</code> literal are the two exceptions where raw type in new code can be used</li> </ul></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload