title: Java Dynamic Casting Object to List<?>
body: <p>I have a situation to where I need to cast <code>Object</code> to <code>List&lt;SomeClassName&gt;</code>.</p>
  
  <p>I get the object value <code>List&lt;SomeClass&gt;</code> from request parameter.</p>
  
  <p>I need to cast this <code>Object</code> into <code>List&lt;SomeClass&gt;</code>. I don't know the <code>SomeClass</code> at compile time.</p>
  
  <p>I can get the class type at run time as <code>String</code>.</p>
  
  <p>Sample:</p>
  
  <pre class="lang-java prettyprint-override"><code>private static Object createList(Object object){
  
        List dd = (List)object;
  
        //the List contains the objects of this class
        Class cls = Class.forName(dd.get(0).getClass().getName());
  
        //I would like to cast this Object to List&lt;thisClass&gt;
  }
  </code></pre>
  
  <p>for example the class is <code>jp.Dto.UserDto</code> then the casting should be like <code>List&lt;jp.dto.UserDto&gt; list = (List&lt;jp.dto.UserDto&gt;)Object;</code> but the problem here is I don't know <code>jp.dto.UserDto</code> class at compile time. I can get this at run time only.</p>
  
  <p>How this can be achieved?</p>