we have classes M-A1 (M loaded by class loader A1) and M-A2 (M loaded by classloader A2). Imagine we also have another class, Test-A1, with a method upcastM() that looks like this:
Because the class Test is loaded by A1, its symbolic link M is also loaded by A1. So we are going to upcast a given object to M-A1. When this method is called with an instance of the class M-A1 as an argument, it will return successfully, but if it is called with an instance of M-A2, it will throw a ClassCastException because it is not the same class, according to the JVM.
Originally posted by Ernest Friedman-Hill
Yes, OK. You asked about ClassCastExceptions happening during class loading, but that's not really what you're asking.