title: ClassCastException when casting to the same class
body: <p>I have 2 different Java projects, one has 2 classes: <code>dynamicbeans.DynamicBean2</code> and <code>dynamic.Validator</code>.</p>
  
  <p>On the other project, I load both of these classes dynamically and store them on an <code>Object</code></p>
  
  <pre><code>class Form {
      Class beanClass;
      Class validatorClass;
      Validator validator;
  }
  </code></pre>
  
  <p>I then go ahead and create a <code>Validator</code> object using <code>validatorClass.newInstance()</code> and store it on <code>validator</code> then I create a bean object as well using <code>beanClass.newInstance()</code> and add it to the session.</p>
  
  <pre><code>portletRequest.setAttribute("DynamicBean2", bean);
  </code></pre>
  
  <p>During the lifecycle of the <code>Form</code> project, I call <code>validator.validate()</code> which loads the previously created bean object from the session (I'm running Websphere Portal Server). When I try to cast this object back into a <code>DynamicBean2</code> it fails with a ClassCastException.</p>
  
  <p>When I pull the object back out of the session using</p>
  
  <pre><code>faces.getApplication().createValueBinding("#{DynamicBean2}").getValue(faces);
  </code></pre>
  
  <p>and check the class of it using <code>.getClass()</code> I get <code>dynamicbeans.DynamicBean2</code>.  This is the class I want to cast it to however when I try I get the ClassCastException.</p>
  
  <p>Any reason why I'm getting this?</p>