||Inside Class Loaders|
|Subject:||Casting classes loaded from different effective classloaders|
|In normal circumstances the ClassCastException thrown when casting classes with the same type but with different effective classloaders is the desired behavior but in some cases we may need the cast to succeed. Just like in the examples in the article, we may need to invoke a method on a class loaded with a classloader different from the effective classloader of the instance we pass as an argument (in this case the class names will match but the classloaders will not). One possible workaround, if the class is serializable, is to serialize the instance and then deserialize it within a class loaded by the second classloader (thus creating an instance that has the correct type and the correct effective classloader) and pass the new instance as the argument. Although this works just fine, it's not really a very elegant answer to that problem and maybe you could suggest a better solution?|
Showing messages 1 through 3 of 3.
Casting classes loaded from different effective classloaders
2003-11-19 04:39:16 anonymous2 [View]