Enum static import

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Enum static import

Post by The_Nick »

Hi everybody,
Having an enum declared within a class:

Code: Select all

public class EnumKindOfThing{
public enum Days{MONDAY,SUNDAY};

}
Would it be correct importing the Days's fields MONDAY and SUNDAY in a static way?

import static EnumKindOfThing.Days.*;

i know that the enum fields (MONDAY and SUNDAY in this case) are implicitily final and static. Therefore it should work should not it?

PS: At the moment I cannot test it myself as I cannot use my laptop.

I am sure that import static EnumKindOfThing.*; would work as the enum is seen as a static nested class. However I would like to know the exact above posted example.
Thanks in advance.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: Enum static import

Post by The_Nick »

Solved, yes it works.

The_Nick.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests