title: How can I pass a Type to a generic Class in java?
body: <p>everyone here! I want pass a Type to a generic Type, like Arraylist, how can I do this? I make a simple Example, so that you will know what I want, of course this code is wrong.</p>
  
  <pre><code>public static void passObjType(Object obj) {
  
      Class clazz = obj.getClass();
  
      ArrayList&lt;clazz&gt; arr = new ArrayList&lt;clazz&gt;();
  
  }
  
  public static void main(String[] args) {
  
      HashSet&lt;String&gt; hs = new HashSet&lt;String&gt;();
  
      passObjType(hs);
  }
  </code></pre>
  
  <p>I hope, if I input a HashSet object, the funktion PassObjType() will create a Arraylist with HashSet and If I input a String Object, then it will create a Arraylist with String. How can I do this? </p>