title: Java: private inner class synthesized constructors
body: <p>I have an <code>Outer</code> class which has a <code>private Inner</code> class.</p>
  
  <p>In my <code>Outer</code> class method, I instantiate the <code>Inner</code> class as follows:</p>
  
  <pre><code>Outer outer = new Outer();
  Inner inner = outer.new Inner();
  </code></pre>
  
  <p>The compiler converts this code to:</p>
  
  <pre><code>Outer outer = new Outer();
  Inner inner = new Inner(outer, null);
  </code></pre>
  
  <p>Using reflection shows that the <code>Inner</code> class has the following synthesized constructors:</p>
  
  <pre><code>private Outer$Inner(Outer)
  Outer$Inner(Outer,Outer$Inner)
  </code></pre>
  
  <p>Since the <code>Inner</code> class is <code>private</code>, the compiler adds that <code>private</code> constructor to it so nobody can instantiate that class. But obviously the <code>Outer</code> class should be able to instantiate it, so the compiler adds that other package private constructor which in turn calls the private constructor. Also, since the package-private constructor has that <code>$</code> in its name, normal Java code can't call it.</p>
  
  <p>Question: why synthesize one private and one package-private constructor? Why not synthesize only the package-private constructor and be done with it?</p>