JBoss Community

invoking a method with the help of object instance from a dynamically generated method using javassist

created by rpslive in Javassist Development - View the full discussion

i want to invoke a method with the help of object instance of the same class from within a method which i m generating dynamically with the help of javassist, i m finding it difficult to implement. A similar method is present with javassist called delegator

for reference : with the help of delegator we can call the same method with super

int f(int p, int q) {

        return super.f(p, q);

        }

i wish to generate the method f dynamically and call the base class method f with the help of the object instance of base class which is injected to the dynamically generated class.

int f(int p, int q) {

         return objectInstance.f(p, q);

        }

i m getting this objectInstance before generating this class and use it to set the field which is also being added dynamically to this class.

assume the scenario below for better understanding:

public class A(){

       public A(Object B,Object C){//A's constructor}

       public int f(int p, int q){

              return p+q;

              }

       }

 

main(){

      C c=new C();

      B b=new B();

      A a=new A(b,c);

      dynamic(a);

}

i want to code dynamic(Object objectInstance) i a way such that the dynamically added class looks like...

public class newA(){

       private Object objectInstance; 

       public void setter(Object obj){

              this.objectInstance=obj;

              }

       public Object getter(){

              return this.objectInstance;

              }

       public int f(int p, int q) {

              return objectInstance.f(p, q);

              }

}

Reply to this message by going to Community

Start a new discussion in Javassist Development at Community