Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public abstract class Foo {
  2. ...
  3. public static final int BAR;
  4. public static final int BAZ;
  5. public static final int BAM;
  6. ...
  7. }
  8.  
  9. public static String lookup(int constant) {
  10. switch (constant) {
  11. case Foo.BAR: return "bar";
  12. case Foo.BAZ: return "baz";
  13. case Foo.BAM: return "bam";
  14. default: return "unknown";
  15. }
  16. }
  17.  
  18. public abstract class Foo {
  19. ...
  20. public static final int BAR=0;
  21. public static final int BAZ=1;
  22. public static final int BAM=2;
  23. ...
  24. }
  25.  
  26. public static final int BAR = new Random().nextInt();
  27.  
  28. public class MainClass {
  29. enum Choice { Choice1, Choice2, Choice3 }
  30. public static void main(String[] args) {
  31. Choice ch = Choice.Choice1;
  32.  
  33. switch(ch) {
  34. case Choice1:
  35. System.out.println("Choice1 selected");
  36. break;
  37. case Choice2:
  38. System.out.println("Choice2 selected");
  39. break;
  40. case Choice3:
  41. System.out.println("Choice3 selected");
  42. break;
  43. }
  44. }
  45. }
  46.  
  47. public static final int TAKE_PICTURE = 1;
  48.  
  49. public static int TAKE_PICTURE = 1;
  50.  
  51. public enum Foo
  52. {
  53. BAR("bar"),
  54. BAZ("baz"),
  55. BAM("bam");
  56.  
  57. private final String description;
  58.  
  59. private Foo(String description)
  60. {
  61. this.description = description;
  62. }
  63.  
  64. public String getDescription()
  65. {
  66. return description;
  67. }
  68. }
  69.  
  70. System.out.println(Foo.BAR.getDescription());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement