title: GWT work-around for missing Class.isInstance()
body: <p>I'm trying to write a job scheduling system in GWT that maintains an array of exceptions (<code>Class&lt;? extends Exception&gt;[] exceptions</code>), that might be resolved by retrying the job. For this, if the scheduler catches an exception, I need to see if this exception matches one of the classes in the array. So, I would like to have a function like this:</p>
  
  <pre><code>boolean offerRetry(Exception exception) {
      for (Class&lt;? extends Exception&gt; e: exceptions)
          if (e.isInstance(exception)) return true;
      return false;
  }
  </code></pre>
  
  <p>Unfortunately <code>Class.isInstance(...)</code> isn't available in GWT.</p>
  
  <p>Is there a good work-around for this? My current best guess is something like this:</p>
  
  <pre><code>public static boolean isInstance(Class&lt;?&gt; clazz, Object o) {
      if ((clazz==null) || (o==null)) return false;
      if (clazz.isInterface()) throw new UnsupportedOperationException();
      Class&lt;?&gt; oClazz = o.getClass();
      while (oClazz!=null) {
          if (oClazz.equals(clazz)) return true;
          oClazz = oClazz.getSuperclass();
      }
      return false;
  }
  </code></pre>
  
  <p>Unfortunately, this approach does not support testing against interfaces, and I don't have any idea how to fix that either as <code>Class.getInterfaces()</code> is also not available. But would this approach at least work the same way as Java's <code>Class.isInstance</code> in all other cases, excluding interfaces? Specifically, if I look at <a href="https://code.google.com/p/google-web-toolkit/source/browse/trunk/user/super/com/google/gwt/emul/java/lang/Class.java" rel="noreferrer">GWT's source for Class.java</a>, the <code>getSuperclass()</code> method contains a check of <code>isClassMetadataEnabled()</code>, which might return false (but I don't know in which cases), as it contains a comment saying "This body may be replaced by the compiler".</p>
  
  <p>Or is there a better way entirely to do this?</p>