Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 214659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:23:44+00:00 2026-05-11T18:23:44+00:00

My coworker suggested making several of the Eclipse code-formatting and warning settings to be

  • 0

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”:

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    

The line with the !!! gives me this warning in Eclipse with my new warning settings:

Access to enclosing constructor
WeirdInnerClassJavaWarning.InnerClass()
is emulated by a synthetic accessor
method. Increasing its visibility will
improve your performance.

What does this mean? The warning goes away when I change “private static class” to “protected static class”, which makes no sense to me.


edit: 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:

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();
    }
}

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.

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.

(apologies, I should have called it NestedClass instead of InnerClass to be more clear.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:23:45+00:00Added an answer on May 11, 2026 at 6:23 pm

    You can get rid of the warning as follows:

    package com.example.bugs;
    
    public class WeirdInnerClassJavaWarning {
        private static class InnerClass {
            protected InnerClass() {}  // This constructor makes the warning go away
            public void doSomething() {}
        }
    
        final private InnerClass anInstance;
        {
            this.anInstance = new InnerClass(); 
            this.anInstance.doSomething();
        }
    }
    

    As others have said, Eclipse is complaining because a private class with no explicit constructor cannot be instantiated from outside, except via the synthetic method that the Java compiler creates. If you take your code, compile it, and then decompile it with jad (*), you get the following (reformatted):

    public class Test {
      private static class InnerClass {
        public void doSomething() {}
        // DEFAULT CONSTRUCTOR GENERATED BY COMPILER:
        private InnerClass() {}
    
        // SYNTHETIC METHOD GENERATED BY THE JAVA COMPILER:    
        InnerClass(InnerClass innerclass) {
          this();
        }
      }
    
      public Test() {
        anInstance.doSomething();
      }
    
      // Your instance initialization as modified by the compiler:
      private final InnerClass anInstance = new InnerClass(null);
    }
    

    If you add a protected constructor, the synthetic code is unnecessary. The synthetic code is theoretically, I suppose, slower by a minescule amount than non-synthetic code using a public or protected constructor.

    (*) For jad, I linked to a Wikipedia page … the domain that hosted this program has expired, but Wikipedia links to another that I have not tested myself. I know there are other (possibly more recent) decompilers, but this is the one I started using. Note: It complains when decompiling recent Java class files, but it still does a good job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I had a coworker suggest I refactor my code to use a label
A coworker showed me the following code and asked me why it worked. <span
A coworker and I can't figure out why the EventHandlers in the following code
A coworker of mine suggested I avoid using any gradients in my mobile apps
My coworker and I have encountered a nasty situation where we have to use
A coworker of mine has this problem, apparently after installing Re#, which seems totally
A coworker has been struggling with this problem. The desired result is an installable
A coworker of mine has had issue with Mootools being backward compatible and I
A coworker asked me to look at indexing on some tables because his query
My coworker is new to C# and didn't know about the coalesce operator. So,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.