This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enums and protected modifier

 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I just tried to declare a member of an enum protected and it worked. Protected-access would be exactly the same as the default-access as there will never be a subclass from an enum, is this right?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds right to me.
 
Trond Valen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I partly agree, it is the same as default access, but why is the protected modifier allowed for enum variables when enums can't be "subclassed"? I thought the main principle was that modifiers that make no sense or introduce redundancy are not allowed, just like classes can't be protected or private. In this case, protected is redundant, because it's the same as having no modifiers (default access).

But then again, protected variables are allowed in final classes, and enums can be seen as a special kind of final classes. This brings me to another question: can you always choose access modifiers for class and instance variables regardless of which modifiers the class has?
[ August 31, 2007: Message edited by: Trond Valen ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic