I want to take an existing enum and add more elements to it as follows:
enum A {a,b,c}
enum B extends A {d}
/*B is {a,b,c,d}*/
Is this possible in Java?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
No, you can’t do this in Java. Aside from anything else,
dwould then presumably be an instance ofA(given the normal idea of “extends”), but users who only knew aboutAwouldn’t know about it – which defeats the point of an enum being a well-known set of values.If you could tell us more about how you want to use this, we could potentially suggest alternative solutions.