title: Bytecode manipulation to intercept setting the value of a field
body: <p>Using a library like <code>ASM</code> or <code>cglib</code>, is there a way to add bytecode instructions to a class to execute code whenever the value of a class field is set?</p>
  
  <p>For example, let’s say I have this class:</p>
  
  <pre><code>
     public class Person
     {  
         bool dirty;
         public String name;
         public Date birthDate;
         public double salary;
     }
  </code></pre>
  
  <p>Let’s say a section of code contains this line:</p>
  
  <p><code>
     person.name = "Joe";
  </code></p>
  
  <p>I want this instruction to be intercepted so the <code>dirty</code> flag is set to <code>true</code>.  I know this is possible for setter methods -- <code>person.setName (“Joe”)</code> -- as class methods can be modified by bytecode manipulation, but I want to do the same thing for a <em>field</em>.</p>
  
  <p>Is this possible, and if so, <em>how</em>?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I want to avoid modifying the code section that accesses the class, I'm looking for a way to keep the interception code as part of the <code>Person</code> class.  Are there a pseudo-methods for field access, similar to properties in Python classes?</p>