title: How to pass a list of Class as parameter?
body: <p>I was trying to have a <code>handleException</code> method, which can take an exception object and a list of acceptable exception classes to check if the exception is acceptable and can be retried.</p>
  
  <pre><code>void handleException(Exception e, String... acceptableExceptionNames)
        throws MyException {
  
      boolean isRetryable = false;
  
      for(String acceptableExceptionName: acceptableExceptionNames) {
        try {
          if (Class.forName(acceptableExceptionName).isInstance(e)) {
            isRetryable = true;
            break;
          }
        } catch (ClassNotFoundException e1) {
          continue;
        }
      }
  
      if (isRetryable) {
        // log retryable
      } else {
        // log error
      }
  
      throw new MyException(isRetryable, "Failed");
    }
  </code></pre>
  
  <p>The parameter I pass in is a <code>String... classNames</code> instead of <code>Class&lt;? extends Exception&gt; classes</code>, because if I do something like this:</p>
  
  <pre><code>void handleException(
      Exception e,
      Class&lt;? extends Exception&gt;... acceptableExceptions)
        throws MyException {
      for (Class acceptableException : acceptableExceptions) {
          if (e instanceOf acceptableException) {}
      }
  }
  </code></pre>
  
  <p>The IDE will complain about <code>unknown class acceptableException</code></p>
  
  <p>Anyone knows if there's a way to pass <code>Class&lt;?&gt;</code>? Or a better way to avoid using <code>String classNames</code> and <code>Class.forName()</code>?</p>