title: Creating a list of a custom object from a list of generic "Object" gets ClassCastException
body: <p>So I have code that looks like this:</p>
  
  <pre><code>public void success(List&lt;Object&gt; profiles, Response response) {
  
      List&lt;MyCustomObject&gt; list= new ArrayList&lt;MyCustomObject&gt;();
  
      for (Object profile : profiles) {
              list.add((MyCustomObject) profile);    // this line crashes                        
       }
  
    }
  </code></pre>
  
  <p>So I get a <code>ClassCastException</code> at line noted above.  Can I do this?</p>
  
  <p>Here is what I am TRYING to do, my real code is a bit more complicated:</p>
  
  <p>I have a <code>List</code> that contains two types of Objects.  So, I am using the <code>Object</code> to hold both.  Then, once I receive this list from the server,  I want to break the list into two lists of my Custom Object (For example, <code>List&lt;MyCustomObject&gt;</code> instead of <code>List&lt;Object&gt;</code>.  So I am doing the cast above in my <code>for</code> loop so I can store the incoming generic object into its specific type of object list.</p>
  
  <p>Is there another way to do this?  Am I on the right track?</p>