title: Get Type of ParameterizedType from generic
body: <p>I cannot understand fully how reflect works, so I'm having some trouble trying to register a custom type adapter for my <code>GsonBuilder</code>.</p>
  
  <p>I need to register a type adapter for a <code>List&lt;Something&gt;</code> type.</p>
  
  <p>This is a working code:</p>
  
  <pre><code>    gsonBuilder.registerTypeAdapter(
              new TypeToken&lt;List&lt;MyClass&gt;&gt;() { }.getType(), new ListDeserializer(MyClass.class)
      );
  </code></pre>
  
  <p>The thing is that I have a lot of classes to register my type adapter, and I have a <code>ListDeserializer</code> and <code>SingleDeserializer</code> adapters.</p>
  
  <p>I'm trying to go generic so I just call a function, pass my <code>GsonBuilder</code> and class, and there you go.</p>
  
  <p>Here is my try:</p>
  
  <pre><code>private static &lt;T&gt; void registerTypeAdapter(GsonBuilder gsonBuilder, T clazz) {
      gsonBuilder.registerTypeAdapter(clazz.getClass(), new SingleDeserializer(clazz.getClass()));
      gsonBuilder.registerTypeAdapter(
              new TypeToken&lt;List&lt;T&gt;&gt;() {
              }.getType(), new ListDeserializer(clazz.getClass())
      );
  }
  </code></pre>
  
  <p>It doesn't work for my <code>ListDeserializer</code>. My guess is that since <code>T</code> is a generic parameterized type of <code>List</code>, it cannot detect it at runtime.</p>
  
  <p>Any suggestions?</p>