title: How to track a method result in Java
body: <p>Briefly speaking, I am working on developing a system which is able to give you information about the results provided by the execution of a java program. I have considered the following problem, and I do not know if it is possible to solve it in java.</p>
  
  <p>I have the following classes:</p>
  
  <pre><code>public class ClassA {
      ClassB classB= new ClassB();
      public Integer method1(){
         return classB.method2();
      }
  }
  
  public class ClassB {
      ClassC classC = new ClassC();
      public Integer method2() {
          return this.classC.method3() + this.classC.method4();
      }
  }
  
  public class ClassC {
      public Integer method3() {
          return 3;
      }
      public Integer method4() {
          return 4;
      }
  }
  </code></pre>
  
  <p>So far I can capture each invocation of the methods by using dynamic proxies. In particular, I am using the Proxy and the InvocationHandler objects from the package java.lang.reflect. Here there is the example I followed (<a href="https://www.concretepage.com/java/dynamic-proxy-with-proxy-and-invocationhandler-in-java" rel="nofollow noreferrer">https://www.concretepage.com/java/dynamic-proxy-with-proxy-and-invocationhandler-in-java</a>). </p>
  
  <p>My question is if someone knows how can I give information such as:
  "the return of method1() is generated from the return of method2(), and the return of method2() is in turn generated from the return of method3() and the return of method4()". </p>