1

有没有办法用 AspectJ 捕捉 Object.equals(Object )?我试过了:

@Pointcut("execution (* *(..))")

或者

@Pointcut("call (* *(..))")

但什么也没发生。

4

1 回答 1

2

The first one would only work if you could weave the advice into your JRE/JDK classes. While JDK weaving is possible (I have done it before) it is non-trivial and beyond the scope of this answer. I assume you are an AspectJ beginner, so I would not go that way if I were you.

The second one works if the call to Object.equals is made explicitly from code controlled by you, i.e. by code you weave your aspect into. If the calls are made by JDK classes, you are back at option 1, JDK weaving. If the calls are made by your own code, you are fine. If they are made by 3rd party libraries, you can still use binary weaving, creating new versions of the 3rd party class files and creating replacement JARs for them. As an alternative, you can use LTW (load-time weaving) and weave them during class-loading.

于 2013-05-03T10:47:58.853 回答