title: dynamically create an array Class in Java
body: <p>I am trying to write this function:</p>
  
  <pre><code>public static Class arrayTypeFor(Class elementType)
  {
       // ... implementation ???
  }
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>arrayTypeFor(int.class); // this should return a Class which is equal to int[].class
  </code></pre>
  
  <p>How do I do this?</p>
  
  <p>I thought about doing this (but it looks pretty inefficient to me).</p>
  
  <pre><code>Array.newInstance(elementCType, 1).getClass();
  </code></pre>