title: how to cast arraylist to a class
body: <p>I am working on a shopping cart, and am getting an exception that an <code>ArrayList</code> cannot be cast to a <code>ShoppingCart</code>. How do I cast an <code>ArrayList</code> to this class?</p>
  
  <h2>Code</h2>
  
  <pre><code>ShoppingCart shoppingCart;
  shoppingCart = (ShoppingCart) session.getAttribute("shoppingCart");
  if(shoppingCart == null){
      shoppingCart = new ShoppingCart();
  }
  </code></pre>
  
  <p>I got this error</p>
  
  <pre><code>java.lang.ClassCastException: java.util.ArrayList cannot be cast to business.ShoppingCart
  </code></pre>
  
  <p>which points to </p>
  
  <pre><code>shoppingCart = (ShoppingCart) session.getAttribute("shoppingCart");
  </code></pre>