Reputation:
I have a confusion here.
If I cannot declare a class as static, how does enum works? It looks like a static class, because it gets instantiated itself and can be called anywhere. Looks like I can use enum almost like other static fields.
Is it safe to use enum?
Upvotes: 8
Views: 181
Reputation: 3274
Each enum which you are declaring inside an enum type is static member of your enum type.And the type of your enum variables is the type of your enum,in short they are self typed.
Upvotes: 0
Reputation: 198033
enum
types are automatically static. You can't have a non-static
enum, so the static
is implied.
Nested enum types are implicitly static. It is permissible to explicitly declare a nested enum type to be static.
Upvotes: 11