title: Eclipse warning about synthetic accessor for private static nested classes in Java?
body: <p>My coworker suggested making several of the Eclipse code-formatting and warning settings to be more rigorous. The majority of these changes make sense, but I get this one weird warning in Java. Here's some test code to reproduce the "problem":</p>
  
  <pre><code>package com.example.bugs;
  
  public class WeirdInnerClassJavaWarning {
      private static class InnerClass
      {
          public void doSomething() {}
      }
  
      final private InnerClass anInstance;
  
      {
          this.anInstance = new InnerClass();   // !!!
          this.anInstance.doSomething();
      }
  }
  // using "this.anInstance" instead of "anInstance" prevents another warning,
  // Unqualified access to the field WeirdInnerClassJavaWarning.anInstance    
  </code></pre>
  
  <p>The line with the !!! gives me this warning in Eclipse with my new warning settings:</p>
  
  <blockquote>
    <p>Access to enclosing constructor
    WeirdInnerClassJavaWarning.InnerClass()
    is emulated by a synthetic accessor
    method. Increasing its visibility will
    improve your performance.</p>
  </blockquote>
  
  <p>What does this mean? The warning goes away when I change "private static class" to "protected static class", which makes no sense to me.</p>
  
  <hr>
  
  <p><strong>edit:</strong> I finally figured out the "correct" fix. The real problem here seems to be that this nested private static class is missing a public constructor. That one tweak removed the warning:</p>
  
  <pre><code>package com.example.bugs;
  
  public class WeirdInnerClassJavaWarning {
      private static class InnerClass
      {
          public void doSomething() {}
          public InnerClass() {}
      }
  
      final private InnerClass anInstance;
  
      {
          this.anInstance = new InnerClass();
          this.anInstance.doSomething();
      }
  }
  </code></pre>
  
  <p>I want the class to be a private nested class (so no other class can have access to it, including subclasses of the enclosing class) and I want it to be a static class.</p>
  
  <p>I still don't understand why making the nested class protected rather than private is another method of fixing the "problem", but maybe that is a quirk/bug of Eclipse.</p>
  
  <p>(apologies, I should have called it NestedClass instead of InnerClass to be more clear.)</p>