Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When two class loaders load a class, you actually have two copies of the class. In your scenario when you do something like this </p> <pre><code>StaticClass s = (StaticClass)newInstance2; </code></pre> <p>Then by default your default system class loader comes into picture for casting. Since the newInstance2 is loaded from another classloader therefore it will give a ClassCastException. This will not work - they are represented by two different Class objects inside the JVM and the cast will fail.</p> <p>For more details refer to the following articles and forum entries:</p> <ol> <li><p><a href="http://onjava.com/pub/a/onjava/2003/11/12/classloader.html" rel="nofollow noreferrer">http://onjava.com/pub/a/onjava/2003/11/12/classloader.html</a></p></li> <li><p><a href="http://java.sun.com/developer/technicalArticles/Networking/classloaders/index.html" rel="nofollow noreferrer">http://java.sun.com/developer/technicalArticles/Networking/classloaders/index.html</a></p></li> <li><p><a href="http://java.sun.com/docs/books/jvms/second_edition/html/ConstantPool.doc.html" rel="nofollow noreferrer">http://java.sun.com/docs/books/jvms/second_edition/html/ConstantPool.doc.html</a></p></li> <li><p><a href="http://www.coderanch.com/t/380416/java/java/Loading-same-class-two-different" rel="nofollow noreferrer">http://www.coderanch.com/t/380416/java/java/Loading-same-class-two-different</a></p></li> <li><p><a href="https://stackoverflow.com/questions/4013047/different-classloaders-cause-classcastexception-when-persisting-data-via-spring">Different classloaders cause ClassCastException when persisting data via Spring</a></p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload