title: NoSuchMethodException when parameter of java.lang.Integer is passed in constructor (Reflection)
body: <p>I am trying to declare an <code>ArrayList</code> using Reflection. Below is my code</p>
  
  <pre><code>public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, SecurityException {
      String intClass="java.lang.Integer";   //This string will be replaced by a string taken from user which will be a class name.
      Class classOf=Class.forName("java.util.ArrayList");
      Class[] parameterslist ={Class.forName(intClass)};
      Constructor constructorOfClass=classOf.getConstructor(parameterslist);
  }
  </code></pre>
  
  <p>When I run this code I get</p>
  
  <pre><code>Exception in thread "main" java.lang.NoSuchMethodException: java.util.ArrayList.&lt;init&gt;(java.lang.Integer)
  </code></pre>
  
  <p>When I modify parameterslist as</p>
  
  <pre><code>Class[] parameterslist={int.class}
  </code></pre>
  
  <p>it works but I have to take the name of parameter class as input from a user, so I can't directly write <code>int.class</code>.</p>
  
  <p>I have already searched about the difference between <code>Class.forName()</code> and <code>Classname.class</code> but answers like <a href="https://stackoverflow.com/questions/12337439/distinction-between-classobject-getclass-classname-class-and-class-fornameclas">this</a> conclude that they are same.
  I just want to know why we cannot use <code>Class.forName()</code> object to pass as a parameter to <code>ArrayList</code> constructor and how does it work when I write <code>int.class</code>? If <code>Class.forName()</code> is not the right way then how can we make an object of a classname taken as input from a user?</p>