拦截方法调用 [英] Intercepting method calls

查看:96
本文介绍了拦截方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个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的?请参见这里和<一href="http://deansserver.co.uk/~dean/2011/07/18/aspect-oriented-android-development-tool-integration/"相对=nofollow>此处切面/ Android的信息。

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

这篇关于拦截方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆