Guest User

Untitled

a guest
Aug 10th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. Using Java enums from different classes?
  2. public class Test
  3. {
  4. // ...
  5. public enum Status {
  6. Opened,
  7. Closed,
  8. Waiting
  9. }
  10. // ...
  11. }
  12.  
  13. public class UsingEnums
  14. {
  15. public static void Main(String[] args)
  16. {
  17. Test test = new Test(); // new Test object (storing enum)
  18.  
  19. switch(test.getStatus()) // returns the current status
  20. {
  21. case Status.Opened:
  22. // do something
  23. // break and other cases
  24. }
  25. }
  26. }
  27.  
  28. switch(test.getStatus()) // returns the current status
  29. {
  30. case Opened:
  31. // do something
  32. // break and other cases
  33. }
  34.  
  35. Test test = new Test(); // new Test object (storing enum)
  36.  
  37. switch(test.getStatus()) // returns the current status
  38. {
  39. case Test.Status.Opened:
  40. // do something
  41. // break and other cases
  42. }
  43.  
  44. case Opened:
  45.  
  46. case Test.Status.Opened:
  47.  
  48. an enum switch case label must be the unqualified name of an enumeration constant
Add Comment
Please, Sign In to add comment