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

  • Home
  • SEARCH
  • 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 8376109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:20:57+00:00 2026-06-09T15:20:57+00:00

I found this construct in some code. Is there any benefit to have a

  • 0

I found this construct in some code.

Is there any benefit to have a private static class implement A? This reminded me of the Pimpl idiom in C++. Is there any benefit to using the Pimpl idiom in Java?

public abstract class A {
    public void doStuff();

    public static A getNewInstance() {
       return new AImpl();
    }

    private static class AImpl extends A {
        public void doStuff()  {
           ....
        }    
    } 

}
  • 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-06-09T15:20:59+00:00Added an answer on June 9, 2026 at 3:20 pm

    Is there any benefit to have a private static class implement A?

    Well, it hides the implementation away completely, so from an encapsulation point of view it’s quite nice. One situation I’ve seen this in a few times is custom comparators. For example:

    public class Person
    {
        public static final Comparator<Person> NAME_COMPARATOR = new NameComparator();
        public static final Comparator<Person> AGE_COMPARATOR = new AgeComparator();
    
        // Name, age etc properties
    
        private static class NameComparator implements Comparator<Person>
        {
            ...
        }
    
        private static class AgeComparator implements Comparator<Person>
        {
            ...
        }
    }
    

    There’s no real need for the comparator implementation classes to be visible outside Person, and it’s nice to be able to get an instance easily via the public static field.

    No callers need to know the implementation – there could just be one comparator class which takes parameters, for example – they just express which comparator they want via the constants. (You could equally use an enum for this, of course.)

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

Sidebar

Related Questions

I am porting some code from C to C++ and I found this code:
I'm trying to implement code for nested commenting which I found at http://www.jongales.com/blog/2009/01/27/php-class-for-threaded-comments/ .
found this little code snippet that seems to do what i want, but im
Found this is some example CSS I was reading and I'm having a hard
Found this question that explained a way to communicate between layers. However there is
I found this code on the internetz, it checks the current page url; function
What I want to do: run some prerequisite code whenever instance of the class
I just found a bug in some code I didn't write and I'm a
I found these lines in some code I was maintaining, which was failing in
I'm trying to parse some css files using a code project parser found here

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.