daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top