Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Using Java enums from different classes?
- public class Test
- {
- // ...
- public enum Status {
- Opened,
- Closed,
- Waiting
- }
- // ...
- }
- public class UsingEnums
- {
- public static void Main(String[] args)
- {
- Test test = new Test(); // new Test object (storing enum)
- switch(test.getStatus()) // returns the current status
- {
- case Status.Opened:
- // do something
- // break and other cases
- }
- }
- }
- switch(test.getStatus()) // returns the current status
- {
- case Opened:
- // do something
- // break and other cases
- }
- Test test = new Test(); // new Test object (storing enum)
- switch(test.getStatus()) // returns the current status
- {
- case Test.Status.Opened:
- // do something
- // break and other cases
- }
- case Opened:
- case Test.Status.Opened:
- an enum switch case label must be the unqualified name of an enumeration constant
Add Comment
Please, Sign In to add comment