2011-05-05

AspectJ: this() vs. target()

this() and target() are AspectJ poincuts for collecting context. What is the difference between them?

this()


That is the Java this object at the matching point.

target()


That is the Java object on which the method is called (or the object whose field is accessed).


… So, what’s the difference in practice? It turns out, it depends on the execution model you use - whether it’s execution or call.

Execution example


execution( void Dog.bark() ) && this( thisObject ) && target( targetObject )
thisObject will be a dog instance. targetObject will be the same dog instance. (If you’re wondering why, it depends on how AspectJ works under the hood - for execution it builds in your advice into the advised method.)

Call example


call( void Dog.bark() ) && this( thisObject ) && target( targetObject )
thisObject will be the instance that called dog.bark(). It could be any class that made this call. targetObject will, still, be a dog instance. (If you’re wondering why, it depends on how AspectJ works under the hood - for call it builds in your advice at the method call, not inside it.)

8 comments:

  1. Thanks for joining us! Each essay writer on masterpapers team is capable of completing assignments from high school essays to PhD dissertations. Furthermore, we will write an essay for you that is representative of the key concepts within your field.

    ReplyDelete
  2. Your post was interesting and effective. Good luck with your upcoming updates!grocery store springfield il

    ReplyDelete
  3. The explanation was excellent. I learned a lot! Thanks for sharing this resource.

    estates planning Fort Worth TX

    ReplyDelete
  4. Your writing style is engaging, and your blog is a treasure of information. Thanks!

    financial advisory companies fort worth tx

    ReplyDelete
  5. You’ve done a great job presenting this information in a clear and organized way. It’s easy to follow and understand!

    chip eligibility pa

    ReplyDelete
  6. This was exactly the information I needed, presented clearly and organized well.

    public accounting firms

    ReplyDelete
  7. Without a doubt, this post is incredible. Every time I read your blog, I’m captivated by the way you explain things so clearly and effectively.

    fine wine store

    ReplyDelete
  8. This is such a thought-provoking read. Your insights on this topic made me reconsider my views. Keep up the excellent work!

    sell home as is fast Ponte Vedra FL

    ReplyDelete