title: How to get the parameter values of a called method in java?
body: <p>I'm trying to get some runtime information to do some debugging. Is there a way to access the parameters actually passed to a method?</p>
  
  <p>I know the calling class and method, but not the parameters and their value at runtime. Any Ideas how to solve this? Thanks in advance.</p>
  
  <p>My code so far:</p>
  
  <pre><code>//get the class I wanna know something about out of the call history
  StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
  String callerMethod = stacktrace[2].getMethodName();
  
  //load the class to get the information
  Class&lt;?&gt; c = Class.forName(stacktrace[2].getClassName());
  Method[] methods = c.getMethods();
  Class&lt;?&gt;[] parameters = methods[1].getParameterTypes();
  
  //get the parameter data
  (parameters[y].isArray()? parameters[y].getComponentType() : parameters[y]).getName();
  
  //TODO: how about the parameter value at runtime?
  </code></pre>
  
  <p>The code has to be generic for all Classes I will implement. Example of usage:</p>
  
  <pre><code>public class doClass() {
    public void doSomething(Object o) {
      //here comes my debug line
      magicDebugger(level);
    }
  }
  </code></pre>
  
  <p><code>level</code> is the switch/trigger to activate console/db/file/mail output or whatever of some information</p>
  
  <p>I expect following output (maybe there's some System.out.println in the magicDebugger class):</p>
  
  <pre><code>[debug] caller: com.company.package.doClass.doSomething(Object o); value of o at runtime = java.lang.String "test"
  </code></pre>