user1917885
user1917885

Reputation:

Does enum means static class?

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

Answers (2)

Renjith
Renjith

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

Louis Wasserman
Louis Wasserman

Reputation: 198033

enum types are automatically static. You can't have a non-static enum, so the static is implied.

JLS 8.9:

Nested enum types are implicitly static. It is permissible to explicitly declare a nested enum type to be static.

Upvotes: 11

Related Questions