我想在类方法之间插入以动态扩展对象。
我已经知道 java.lang.reflect.Proxy 的东西,但是它太有限了,无法进行真正的插入。
来自 Using java.lang.reflect.Proxy to Interpose on Java Class Methods ,第一个限制是:
(...) the method must be called through an instance of the proxy class. So nested methods calls, for instance, would not be intercepted.
最糟糕的是:
(...) the method must have been defined in an Interface that is implemented by the object being proxied. It can not be called through an instance of a class that does not implement an interface.
我想在运行时扩展的对象没有实现任何接口(interface),最糟糕的是,我需要覆盖的方法是嵌套的和私有(private)的。
我知道这在 Python 和 C 中相当容易,上面引用的文章说这是可能的:
The next article in this series will illustrate some techniques for overcoming these limitations.
很遗憾,我找不到这篇文章。
最佳答案
关于java - 插入 Java 类方法(无接口(interface)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9061478/