This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Enums and inheritance  RSS feed

 
Ranch Hand
Posts: 150
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have learned that an enum cannot extend another enum.
However I have the following problem:



A and B have slightly different semantics. I do not want to use B in place where A is expected.
Still the enumeration literals have the same meanings so I would want to have something like


which of course does not compile.
Is there a pattern to solve this problem elegantly?

Thanks,

Hans
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please say more about the problem, as enums are
used to introduce meaningful semantics. For example,
if 'A' really refers to Auto and 'B' to Boyscout, where
is the confusion in saying, Auto.OLD and elsewhere
Boyscount.OLD?
Jim ...
 
Sheriff
Posts: 23451
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Marcus Didius Falco wrote:I do not want to use B in place where A is expected.


But if B extended A, then you could do that. So apparently that's a reason why B should not extend A.

But anyway, Jim Hoglund is on the right track. Examples which use names like A and B aren't always useful.
 
Markus Schmider
Ranch Hand
Posts: 150
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I try to be more specific although the original problem uses German judical language which I cannot translate precisely


The original enums have many more literals and TypeOfEducation is a superset of Schooltype.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!