title: Why is it impossible to construct private objects through reflection in Java
body: <p>I clearly set the constructor's setAccessible to true, but why is it still an error! can you tell me how to fix it</p>
  <pre><code>public class Person {
      // fields...
  
      private Person(String name, int age, String address, int num) {
          this.name = name;
          this.age = age;
          this.address = address;
          this.num = num;
          System.out.println(&quot;private full-constructor be created&quot;);
      }
  
  }
  </code></pre>
  <p>// error happend ?! why?</p>
  <pre><code>public static void operatePrivateConstructorFullParameter(Class&lt;? extends Person&gt; clzz) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
      Constructor&lt;? extends Person&gt; constructor = clzz.getConstructor(String.class, int.class, String.class, int.class);
      constructor.setAccessible(true);
  
      Person person = constructor.newInstance(&quot;Miao&quot;, 18, &quot;MOON&quot;, 88);
  }
  
  
  public static void main(String[] args) throws Exception {
      Class&lt;? extends Person&gt; clzz = Person.class;
      operatePrivateConstructorFullParameter(clzz);
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/IdgOM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IdgOM.png" alt="enter image description here" /></a></p>