title: Replace Java types in compile/runtime
body: <p>I have a list of types that I want to replace, for logging purposes, but without changing my code (the logging part it's just to use esporadically). I'm looking for an easy way to create some kind of proxies for my class fields, in order to know, in runtime, when my class fields are changed or, when I don't have the class source code (e.g. LinkedList), when class methods are called.</p>
  
  <p>As an example, if I have this code, which is a class that belongs to me and I just need to be warned about MyClass field state changes:</p>
  
  <pre><code>public class MyClass {
  
     private LinkedList&lt;Integer&gt; myList;
  
     private int myInteger;
  
     public void myMethod() 
     {
        myInteger = 15;
        myList = new LinkedList&lt;Integer&gt;();
     }
  
     public void myOtherMethod()
     {
        myList.add(1);
     }
  
     public LinkedList&lt;Integer&gt; getMyList() {
        return myList;
     }
  }
  </code></pre>
  
  <p>I need to know, in runtime (but the code modification can be done in compile time), every time that someone changes the value of <code>myInteger</code>, add an element to <code>myList</code> and change <code>myList</code> referenced <code>LinkedList</code>. I think that the solution shouldn't be done entirely with code analysis, since list references can be passed by parameter to everywhere, like in <code>getMyList()</code></p>
  
  <p>In this case, the logging it's just for fields, wheter they're primitive or objects. For types that I don't have the code (like LinkedList), I'll be happy if I get notified when some method is called or any public field it's read or written.</p>