Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The third constructor is a <em>synthetic</em> constructor generated by the compiler, in order to allow access to the private constructor from the outer class. This is because inner classes (and their enclosing classes' access to their private members) only exist for the Java language and not the JVM, so the compiler has to bridge the gap behind the scenes.</p> <p>Reflection will tell you if a member is synthetic:</p> <pre><code>for (Constructor c : aClass.getDeclaredConstructors()) { System.out.println(c + " " + c.isSynthetic()); } </code></pre> <p>This prints:</p> <pre><code>a.TestNested$A(a.TestNested) false private a.TestNested$A(a.TestNested,int) false a.TestNested$A(a.TestNested,int,a.TestNested$1) true </code></pre> <p>See this post for further discussion: <a href="https://stackoverflow.com/q/921025/697449">Eclipse warning about synthetic accessor for private static nested classes in Java?</a></p> <p><strong>EDIT:</strong> interestingly, the eclipse compiler does it differently than javac. When using eclipse, it adds an argument of the type of the inner class itself:</p> <pre><code>a.TestNested$A(a.TestNested) false private a.TestNested$A(a.TestNested,int) false a.TestNested$A(a.TestNested,int,a.TestNested$A) true </code></pre> <p>I tried to trip it up by exposing that constructor ahead of time:</p> <pre><code>class A { A() { } private A(int a) { } A(int a, A another) { } } </code></pre> <p>It dealt with this by simply adding another argument to the synthetic constructor:</p> <pre><code>a.TestNested$A(a.TestNested) false private a.TestNested$A(a.TestNested,int) false a.TestNested$A(a.TestNested,int,a.TestNested$A) false a.TestNested$A(a.TestNested,int,a.TestNested$A,a.TestNested$A) true </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload