title: Simple way to get an array class type of a generic?
body: <p>I've got a little code snippet that's supposed to make parsing JSON arrays simpler. My idea was originally as follows (pseudo-Java):</p>
  <pre><code>  public &lt;T&gt; T[] parseAsArray(String content, Class&lt;T&gt; valueType) {
      return objectMapper.readValue(content, T[].class); // doesn't work as you can't just go T[].class
    }
  </code></pre>
  <p>So then I fiddled around with the code. And then some more. And some more.</p>
  <p>Eventually I landed at the following mess, which does work, but requires me to create a new array instance, just so I could fetch its array class type, not to mention all the casting.</p>
  <pre><code>  public &lt;T&gt; T[] parseAsArray(String content, Class&lt;T&gt; valueType) {
      Class&lt;T[]&gt; tArrClass = (Class&lt;T[]&gt;) Array.newInstance(valueType, 0).getClass();
      return (T[]) objectMapper.readValue(content, tArrClass);
    }
  </code></pre>
  <p>Isn't there a simpler way? All I'm really trying to do is, how can I go from <code>T</code> to <code>T[]</code> and with it to <code>T[].class</code>?</p>