1 Reply Latest reply on Jul 19, 2005 9:44 PM by chiba

    ClassCastException after javassist manipulation

    cat4hire

      Hi,
      I've got a class that implements and interface, let's say:

      public class MyClass implements MyInterface{}

      I use javassist to add the method from another class, and to obtain a new object of kind MyClass with the added method. It works, and in fact if I perform introspection, I can find the added method and I can see that getClass().getName() gives me MyClass. However, if I try to cast the class from MyInterface (that works) to MyClass it does not work, and an exception is thrown:

      MyClass myclazz = new MyClass();
      MyInterface object = .....// manipulation of myclazz
      myclazz = (MyClass) object; // ClassCastException here!

      Now, I use the interface in all the manipulation process, but I don't think it can be the problem. In fact, as I told you, if I print the class information, I can see that the manipulated class is of the MyClass class, and implements the MyInterface. Any idea? I'm using javassist 3.

      Thanks,
      Luca