1 Reply Latest reply on Mar 24, 2005 10:08 AM by chiba

    javassist.expr.MethodCall.getClassName() question (bug?)

    bammi

      javassist.expr.MethodCall.getClassName() is supposed to return the className of the target object that the method call is on. If the target object implements an interface, and this methodCall represents a call to one of the methods of the interface that the taregt object implements, then javassist.expr.MethodCall.getClassName() returns the classname of the interface rather than the classname of the target object that implements the interface method. Am i misunderstanding the intent of getClassName() or is this a bug? If this is not a bug, how do i navigate to get the className of the Object that implements the interface?

      Example:

      public interface Greeting {
      public void speak();
      }

      public class HelloWorld implements Greeting {
      public void speak() {
      System.out.println("Hello, world!");
      }
      }

      in main:

      Greeting h = new HelloWorld();
      h.speak();

      in the MethodCall().getClassName() for this method call, i get "Greeting", i was expecting to get "HelloWorld" as that is the Class of the target object "h" in this methodCall.

      Thanks
      bammi@memento-inc.com

        • 1. Re: javassist.expr.MethodCall.getClassName() question (bug?)
          chiba

           

          how do i navigate to get the className of the Object that implements the interface?


          You cannot get the actual class name of the target object.
          This is not the limitation of Javassist.

          Greeting h = new HelloWorld();
          h.speak();


          Since the value of h is determined only at runtime, you cannot know
          the actual class name of the value of h when Javassist is running, i.e.
          compile time or load time.