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 3426742
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:45:09+00:00 2026-05-18T06:45:09+00:00

I recently came across a coding standard claiming that you should never use public

  • 0

I recently came across a coding standard claiming that you should never use public inner enums/classes in Java. This is the first time I’ve encountered this convention, and haven’t been able to find a satisfactory explaniation as to why.

I understand why public inner classes should be avoided, but for what reasons would you never use public nested enums? Or, why is this a bad convention to follow?

  • 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-18T06:45:09+00:00Added an answer on May 18, 2026 at 6:45 am

    Disclaimer: The following are not hard and fast rules. These are just my opinions and personal preferences. I personally find that it makes my code easier to read and easier to maintain.

    First a question. Where did you come across this advice? Did they provide any rationale?

    In my experience, I’ve normally used private nested enums to enhance readability and maintainability of my code. This especially comes into play when you’re performing an integration with another system and you have to send in specific strings or numbers. I find that using an enum makes things easier to read and maintain. In this specific case, the information conveyed by the enum is limited in scope to the class (i.e., it makes no sense outside the class and no one else should need it).

    I can’t think of a definitive reason that says why public inner enums are a bad practice. But here are reasons why I don’t (normally) use them:

    • If the enum is public, it essentially means that it conveys information in a larger scope (i.e., makes sense outside the scope of its parent class and so it probably means that other things are using it). If this is the case, then it might make more sense to make it a standalone enum.
    • I find it ThirdPartyResponseCodes.Success easier on the eyes rather than ThirdPartyIntegrationInterface.ThirdPartyResponseCodes.Success. There is no reason why you cannot name the enum appropriately to provide context and thus make it a standalone enum.
    • I would imagine that the same reasons for not using public inner classes also apply to public inner enums. First of all, if you have an inner class, it may mean that your outer class might benefit from refactoring. Perhaps your outer class is trying to do too much? On the flip side though, there is the benefit of encapsulation and limiting scope, especially if you can make the argument that the inner class only makes sense in the context of the outer class (which should go without saying if it is private). If it is a public inner class, then that probably means that its scope extends past the outer class and thus it would need to be pulled out.
    • If you really do need to use a public nested enum then you should document exactly why you would need it (I haven’t found a reason to do so yet) and why it is better to leave it as an public nested enum and not a public standalone enum.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently came across an IE7 only bug that I thought I'd share so
I recently came across a ASP 1.1 web application that put a whole heap
I was working on some code recently and came across a method that had
I was reading some Java recently and came across something (an idiom?) new to
An interesting issue came up recently. We came across some code that is using
I recently came across a rather unusual coding convention wherein the call for a
Possible Duplicate: What are bitwise operators? Recently I came across a few samples that
I recently came across an interesting line of code that waits until a particular
I recently came across a question where someone asked what architecture we use in
I recently came across this article which explains how to use HTML5 tags in

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.