• Post Reply Bookmark Topic Watch Topic
  • New Topic

Enums and inheritance  RSS feed

 
Markus Schmider
Ranch Hand
Posts: 149
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
 
Jim Hoglund
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 ...
 
Paul Clapham
Sheriff
Posts: 22819
43
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: 149
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!