R
richnjones
Hello all,
I was messing around with enums and am confused about the modifiers I
can apply. I am using Eclipse and am not sure if I am misunderstanding
the error.
Consider this enum
enum Planets {Mercury, Venus}
I can put private/protected/public in front of it. At the moment I
consider it to have package access. This makes perfect sense
I can also add static in front of it. Enum is a class that extends
Object so that kind of makes sense. However I cannot add final in
front of it. Now I dont believe you can extends enums (why would you
want to) so having final might seem a little pointless but i do not
see why you cannot have it for completeness. (You can add final to
variables in Iiterfaces which are implicitly final) Also and more
confusingly when I put final in front of it then Eclipse says it is an
invalid modifier and that I can only have private/protected/public/
abstract/static. When I put abstract in front I get a compile error.
Is Eclipse wrong? Can you put an abstract in front of enums in some
cases? Is there any reason you cannot put final in front? (Assuming
you can use abstract then i can see why final isnt allowed). What use
would an abstract have?
abstract enum Planet {Mercury, Venus} //does not compile
Any help is greatly appreciated
Thanks
R
I was messing around with enums and am confused about the modifiers I
can apply. I am using Eclipse and am not sure if I am misunderstanding
the error.
Consider this enum
enum Planets {Mercury, Venus}
I can put private/protected/public in front of it. At the moment I
consider it to have package access. This makes perfect sense
I can also add static in front of it. Enum is a class that extends
Object so that kind of makes sense. However I cannot add final in
front of it. Now I dont believe you can extends enums (why would you
want to) so having final might seem a little pointless but i do not
see why you cannot have it for completeness. (You can add final to
variables in Iiterfaces which are implicitly final) Also and more
confusingly when I put final in front of it then Eclipse says it is an
invalid modifier and that I can only have private/protected/public/
abstract/static. When I put abstract in front I get a compile error.
Is Eclipse wrong? Can you put an abstract in front of enums in some
cases? Is there any reason you cannot put final in front? (Assuming
you can use abstract then i can see why final isnt allowed). What use
would an abstract have?
abstract enum Planet {Mercury, Venus} //does not compile
Any help is greatly appreciated
Thanks
R