我想检查一些CGLib代理Groovy类,从Java,Groovy生成的方法,以了解什么是返回和参数类型的方法。当然,考虑这个Groovy类:检查来自Java的CGLib代理Groovy类
class Person {
String name
}
Groovy产生的getName()
和setName()
方法的name属性。 getName()
据推测返回String
和setName()
大概需要String
。
但通过使用CGLIB这个类和使用CGLIB的MethodInterceptor,method.getName()
回报getMetaClass
和method.getReturnType()
回报groovy.lang.MetaClass
拦截针对getName
调用时。
有没有办法从MethodInterceptor内部学习实际方法名称和返回类型?
编辑:这里是拦截Person.getName()的调用时调用堆栈:
ExplicitMappingInterceptor.intercept(Object, Method, Object[], MethodProxy) line: 42
GroovyMMTester$A$$EnhancerByCGLIB$$915b5b4.getMetaClass() line: not available
CallSiteArray.createPogoSite(CallSite, Object, Object[]) line: 144
CallSiteArray.createCallSite(CallSite, Object, Object[]) line: 161
CallSiteArray.defaultCall(CallSite, Object, Object[]) line: 45
AbstractCallSite.call(Object, Object[]) line: 108
AbstractCallSite.call(Object) line: 112
GroovyMMTester$Map.configure() line: 18 <-- Person.getName() call is in here, but doesn't show
什么原因使用CGLib而不是[Metaclass](http://groovy.codehaus.org/Evaluating+the+MetaClass+runtime)? – ChrLipp
我想你所调用的是Person对象上的getName(),而不是直接Person.getName()。对? – Alfergon