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();
}
}