Article:
 |
|
Inside Class Loaders
|
| Subject: |
|
Casting classes loaded from different effective classloaders |
| Date: |
|
2003-11-18 12:40:57 |
| From: |
|
schaefera
|
Response to: Casting classes loaded from different effective classloaders
|
|
Hi
As we will see in the next installment this is how J2EE invocation on remote interfaces go around the problem even when you call them within the server. However, the client that receives the class will actually load the class locally (with its own class loader) and then incorporate the values from the object stream. But that requires that the client has a compatible class defintion available and if not deserialization will fail. In the case you have a compatible version the class behind the newly created instance is NOT (if the client uses a different class loader) compatible to the original class because the two class types have different class loaders. Thus to send the data back you need to serialize/deserialze the class again.
In the next part of this article series I will explain a little bit more in detail how J2EE deals with multiple class loaders and talk about serilization/deserialization.
Nevertheless I do not have a more elegant solution to propose even thought I would like to have a possiblity in Java to force a upcast as long as the class types are compatible to avoid wasting a lot of time.
-Andy
|
Showing messages 1 through 1 of 1.
-
Casting classes loaded from different effective classloaders
2008-03-23 02:26:42
j0h4n
[View]
When will we see one?
Maybe making a proxy like so:
class A loaded by a classloader C1 denoted <A,C1>;
another impl of class A loaded on a second instance of a classloader C2 denoted <A,C2>;
whenever we want two classes loaded by diferent classloaders to communicate the jvm allows that by way of automatically creating proxies. In the case where an instance of class B loaded by C1 denoted <B, C1> want's to communicate with <A, C2> the JVM creates a proxy <A2, C1> that resides in the C1 classloader.
I dunno, maybe it's easy said than done?
regards,
johan