title: Checking if a Class<?> is instane of other by reflection
body: <p>I'm trying to create a random generator of any class for stress test purposes.</p>
  
  <p>My generator goals to create any class with default constructor and fill its primitive and String fields (by reflection)</p>
  
  <p>I would like also to fill fields of type Number (Integer, Long, Double....) as they are easily convertible to primitives.</p>
  
  <p>But I couldn't find a simple approach o <code>instanceof</code> between types.</p>
  
  <p>Here is the method</p>
  
  <pre><code>public static &lt;V&gt; Collection&lt;V&gt; createMassiveCollection(Class&lt;V&gt; clazz, int amount, Class&lt;?&gt; collectionType) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
  
          Random r = new Random();
          RandomGenerator rg = new RandomGenerator();
          @SuppressWarnings("unchecked")
          Collection&lt;V&gt; collection = (Collection&lt;V&gt;) collectionType.newInstance();
          for (int i = 0; i &lt; amount; i++) {
              V item = clazz.newInstance();
  
              for (Field field : item.getClass().getDeclaredFields()) {
  
                  if (java.lang.reflect.Modifier.isStatic(field.getModifiers()) || java.lang.reflect.Modifier.isFinal(field.getModifiers()))
                      continue;
  
                  field.setAccessible(true);
  
                  if (field.getType().equals(String.class))
                      field.set(item, rg.nextCompliment());
  
                  else if (field.getType().isPrimitive() &amp;&amp; (field.getType() != boolean.class &amp;&amp; field.getType() != byte.class &amp;&amp; field.getType() != char.class))
                      field.set(item, r.nextInt(1000000));
  
                  else {
                      Constructor&lt;?&gt; c = null;
  
                      try {
                          c = field.getType().getConstructor(String.class);
                      }
                      catch (Exception e) {}
                      if (c != null &amp;&amp; Number.class.isInstance(c.newInstance("1")))
                          field.set(item, field.getType().getConstructor(String.class).newInstance(r.nextInt(1000000) + ""));
                  }
  
              }
  
              collection.add(item);
          }
          return collection;
      }
  </code></pre>
  
  <p>The third if is the one causing problems
  I would like something like: "if <code>Type&lt;C&gt;</code> is subtype of <code>Type&lt;V&gt;</code>"
  but all ways i found need an valid instance of object to check.</p>
  
  <p>ex.
  <code>Number.class.isInstance(field.getType())</code> nor <code>field.getType() instanceof Number</code> works because <code>field.getType()</code> is instance of Type.</p>
  
  <p>Does anyone know if it is possible?</p>
  
  <p>Another question (less important) in my method signature i would like to have </p>
  
  <pre><code>Class&lt;? extends Collection&lt;V&gt;&gt; collectionType
  </code></pre>
  
  <p>but if i do that when i try to call the method like</p>
  
  <pre><code>createMassiveCollection(User.class, 100000, new ArrayList&lt;User&gt;().getClass());
  </code></pre>
  
  <p>the compiler fails! so, to be able to compile i must trust the user is passing some type that extends Collection as parameter</p>