title: How to pass a class type as parameter and cast to it?
body: <p>Why can't I cast an object to a class type that I provide via paramter?</p>
  
  <pre><code>public static checkInstanceOf(Object obj, Class&lt;?&gt; type) {
      return obj instanceof type; //error: type cannot be resolved to a type
  }
  </code></pre>
  
  <p>I'd like to create a utility method that has to use an instanceof check like this in a more detailed routine. What would I have to change?</p>
  
  <p>I'd like to be able to call something like this:</p>
  
  <pre><code>MyUtil.checkInstanceOf(new String(""), MyClass.class);
  </code></pre>