拦截方法调用方法

由网友(缺扣衬衫.)分享简介:我有这个code Foo foo = new Foo();foo.callTheMethod();有没有什么办法可以拦截 Foo.callTheMethod()呼叫而不子类或修改富类,而不必一个富工厂?Is there any way I can intercept the Foo.callTheMethod()...

我有这个code

Foo foo = new Foo();
foo.callTheMethod();

有没有什么办法可以拦截 Foo.callTheMethod()呼叫而不子类或修改类,而不必一个工厂?

Is there any way I can intercept the Foo.callTheMethod() call without subclassing or modifying Foo class, and without having a Foo factory?

编辑:对不起,忘了提,这是Android平台

sorry forgot to mention this is on Android platform.

推荐答案

你有没有考虑的面向方面的编程也许 AspectJ的?请参见这里和此处切面/ Android的信息。

Have you considered aspect-oriented-programming and perhaps AspectJ ? See here and here for AspectJ/Android info.

阅读全文

相关推荐

最新文章