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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:05:26+00:00 2026-05-13T01:05:26+00:00

This is not a question of the new features in enum. This is not

  • 0

This is not a question of the new features in enum.
This is not a question that waits for an answer that says
enum is equivalent to class xyz extends Enum. If you wish to preach on how enums are used, as found in numerous tutorials, please don’t answer.

This question is specifically on how to use the class java.lang.Enum.
Rather it is true that java.lang.Enum cannot be directly extended nor instantiated, right?
It is true that java.lang.Enum is only for the benefit of enum type and nothing else right?

If so, the variable colours is pretty meaningless, right? Even though the compiler allows it.

final static Enum<colors> colours = null;
enum colors {"R","G","B"};

So, what could I possibly equate the variable colours besides null.

of course, compiler won’t allow me to do this

class BaseColour extends Enum<BaseColour>{ ,,,}

but it allows enum an unfair advantage to able to do it as a compiler’s behind-the-curtains manipulation.

I am asking this question because I wish to do something like these

class Reddish extends BaseColour {"Crimson", "Blood", "Pink"};
class Purplish extends BaseColour {"Violet", "Evening Sky", "Brinjal"};
class Greenish extends BaseColour {"Algae", "Leaf"};

I wish to pass any of these, and only any of these, enumerated types into a method

void squeezeColour(BaseColour colourConstraint)
{ ... }

Is it possible?
/** If not, and if you happen to be James Gosling et al, would you kindly consider this for the next version of Java specs? **/

Further addition to question: I forgot to say this …
What I am working on is using an EnumMap or EnumSet and exploiting the contains and range methods. Is that the best I could do?

  • 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-13T01:05:27+00:00Added an answer on May 13, 2026 at 1:05 am

    What an enum actually is, internally, is an integer constant. Or at least, the JVM is free to treat it as one, precisely because of the kind of restrictions that are frustrating you. That makes enums efficient, at the cost of breaking object-orientation.

    I suggest you revert to the old “type checked enum” pattern that was used before enums had syntax.

    class Foo {
    
      // the constants
      public static final Foo RHUBARB = new Foo();
      public static final Foo CUSTARD = new Foo();
    
      // only this class and subclasses can create constants
      protected Foo(){ }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not a technical question, but given that there are a few iPhone
Okay this is not a question of how to get all uniques or How
No, this is not a question about generics. I have a Factory pattern with
I just want to clarify one thing. This is not a question on which
Sorry for this not being a real question, but Sometime back i remember seeing
This question is not so much programming related as it is deployment related. I
This is not exactly a programming question, but it's highly related. We are writing
This question might not seem programming related at first, but let me explain. I'm
This is not a really technical question but is required for a system I
This is a question not really about programming (is not specific to any language

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.