您可能想使用
Pipe而不是反射API:
public class NodeInterceptor { @RuntimeType public static Object intercept(@Pipe Function<Node, Object> pipe,@FieldValue("node") Node proxy) throws Exception { return proxy != null ? pipe.apply(proxy); : null; }}为了使用管道,首先需要安装它。如果您有可用的Java 8,则可以使用
java.util.Function。否则,只需定义某种类型:
interface Function<T, S> { S apply(T t); }你自己 类型的名称和方法无关。安装类型:
MethodDelegation.to(NodeInterceptor.class) .appendParameterBinder(Pipe.Binder.install(Function.class));
但是,您确定反射部分是应用程序性能问题的关键点吗?您是否正确缓存了生成的类,并且缓存有效地工作了?反射API比其声誉更快,尤其是因为使用字节伙伴倾向于隐含单态调用站点。
最后,一些一般性反馈。你在打电话
.implement(EnhancedNode.class).intercept(FieldAccessor.ofBeanProperty())
多次。这没有作用。另外,
method.getDeclaringClass().cast(node)没有必要。反射API为您执行转换。



