Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://java.sun.com/javase/6/docs/api/java/lang/Class.html#isAssignableFrom%28java.lang.Class%29" rel="nofollow noreferrer"><code>Class.isAssignableFrom()</code></a> essentially checks the <a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.10" rel="nofollow noreferrer">subtyping relation</a>. "subtype" and "subclass" are two different concepts. The class hierarchy (i.e. subclassing) is only a part of subtyping.</p> <p><a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.10.1" rel="nofollow noreferrer">Primitive types</a> and <a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.10.3" rel="nofollow noreferrer">array types</a> have special cases for subtyping.</p> <p>The rules for subtyping of array types are like this (note that "><sub>1</sub>" means "is a directy subtype of"):</p> <blockquote> <ul> <li>If <code>S</code> and <code>T</code> are both reference types, then <code>S[]</code> ><sub>1</sub> <code>T[]</code> iff <code>S</code> ><sub>1</sub> <code>T</code>.</li> <li><code>Object</code> ><sub>1</sub> <code>Object[]</code></li> <li><code>Cloneable</code> ><sub>1</sub> <code>Object[]</code></li> <li><code>java.io.Serializable</code> ><sub>1</sub> <code>Object[]</code></li> <li>If <code>p</code> is a primitive type, then: <ul> <li><code>Object</code> ><sub>1</sub> <code>p[]</code></li> <li><code>Cloneable</code> ><sub>1</sub> <code>p[]</code></li> <li><code>java.io.Serializable</code> ><sub>1</sub> <code>p[]</code></li> </ul></li> </ul> </blockquote> <p>The important part for your question is the very first item: an array type <code>X[]</code> is a subtype of an array type <code>Y[]</code> if and only if the component type <code>X</code> is a subtype of the component type <code>Y</code>.</p> <p>Also note that strictly speaking neither <code>Object[]</code> nor <code>String[]</code> are classes. They are "only" types. While every class implicitly is a type, the reverse is not true. Another example of types that are not classes are the primitive types: <code>boolean</code>, <code>byte</code>, <code>char</code>, <code>short</code>, <code>int</code>, <code>long</code>, <code>float</code> and <code>double</code> are types, but they are <em>not</em> classes.</p> <p>Another cause for confusion is the fact that you can easily get <code>java.lang.Class</code> objects representing those <em>types</em>. Again: This does <em>not</em> mean that those types are classes.</p>
    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.
 

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