ClassCast Exception

I have two Jar files: J1 and J2. J1 contain class C1. J2 contain class C2 and class C3.

public class C1{}

public class C2 extends C1{}

public class C3

{

public C1 get_class()

{

return new C2();

}

}

I put J1 on client side and J2 on server side. Then I try to load C3 from J2 dynamically on client side. I create instance of C3 and invoke method get_class(). On output on client side I have Object obj than has class name C2. but I can not cast it to C1. If I call: C1 c = (C1)obj; I have got ClassCast Exception. How to fix this code?

[602 byte] By [Yurya] at [2007-10-3 4:51:49]
# 1
You should put code here representing a minimal test case that causes the problem, otherwise it would be magic to help you finding a solution.
stefan.schulza at 2007-7-14 22:56:33 > top of Java-index,Core,Core APIs...
# 2

> I put J1 on client side and J2 on server side. Then I

> try to load C3 from J2 dynamically on client side. I

> create instance of C3 and invoke method get_class().

> On output on client side I have Object obj than has

> class name C2. but I can not cast it to C1. If I

> call: C1 c = (C1)obj; I have got ClassCast

> Exception. How to fix this code?

For a VM to access a class that class must exist in the VM.

Right now your only choice is to have jars on both sides.

jschella at 2007-7-14 22:56:33 > top of Java-index,Core,Core APIs...