Matching a Joinpoint Based on Interface Implementation

Something I had a little trouble with while toying with aspects was getting a joinpoint pattern to match methods where the return type implemented some interface. I tried the following:

execution(public AnInterface *(..))

But, that only works if I am returning the explicit interface as the return type… it doesn’t match if the return type happens to implement that interface. However, according to the AspectJ Programming Guide, we’ll need to use the + operator to match a subtype. So, simply put, we just modify the above joinpoint pattern:

execution(public AnInterface+ *(..))

That does the trick…

You can leave a response, or trackback from your own site.

Facebook comments:

Leave a Reply

Subscribe to RSS Feed Follow me on Twitter!