0

I have problem with use of CGLib. I have defined a MethodInterceptor, but when I call method.getName() in the intercept method I get only the result from the toString() method ... Why? I don't understand that, because I never call the toString() method directly

public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
      ....
      method.getName();
      return something;
}

when i call method on proxy object i get toString but i call different method. Thx for every idea.

---UPDATE---- Creating Enhancer:

Enhancer enhancer = new Enhancer();
enhancer.setCallback(new GetMethodsInterceptor());
enhancer.setSuperclass(Book.class);

I use proxy object

 ((Book)enhancer.create()).getValue();

where GetMethodsInterceptor() is

public class `GetMethodsInterceptor` implements MethodInterceptor {

    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        return method.getName();
    }
}
bajky
  • 332
  • 6
  • 17
  • You appear to be calling `method.getName()` but are not doing anything with the String returned. Just calling this method accomplishes nothing, but instead you need to do something with the String object that it produces, either by printing it out, or assigning it to a variable. – Hovercraft Full Of Eels Feb 29 '16 at 23:31
  • yes i try to return method.getName() and value is still toString . – bajky Feb 29 '16 at 23:34
  • Show it -- show real code and real results please. – Hovercraft Full Of Eels Feb 29 '16 at 23:34
  • ok i try to update my question – bajky Feb 29 '16 at 23:36
  • What is the value of the variable 'method' ? Can it possibly be that it is the 'toString' method of some class, and therefore `method.getName()` will return `toString`. – FredK Feb 29 '16 at 23:56

0 Answers0