title: How to pass an object to a method using reflection in java
body: <p>I am working on some code which takes a string input dynamically , so i chose reflection as i didnt find any other better approach for it ,</p>
  <p><strong>My current code:</strong></p>
  <pre><code>Class xyzClass = Class.forName(&quot;com.example.Xyz&quot;);
  
  Object abcObj =  abcService.generateAbcObj(&quot;some string input&quot;);
  Method method = xyzClass.getDeclaredMethod(&quot;add&quot;, abcObj); // i want to pass this abcObj to this declared method add but getDeclaredMethod takes class as a parameter
  </code></pre>
  <p>Can anybody suggest way to do in reflection as i want it in a dynamic way or any other way to achieve it in a better sense ?</p>