fork download
  1. class IndirectReference<E> {
  2. private E ref;
  3.  
  4. public IndirectReference(E ref) {
  5. this.ref = ref;
  6. }
  7.  
  8. public E get() {
  9. return ref;
  10. }
  11.  
  12. public void set(E ref) {
  13. this.ref = ref;
  14. }
  15. }
  16.  
  17. enum Enum { E1, E2 }
  18.  
  19. class Main {
  20. private IndirectReference<Enum> e;
  21.  
  22. public Enum get() {
  23. return e.get();
  24. }
  25.  
  26. public void foo(IndirectReference<Enum> ref) {
  27. this.e = ref;
  28. }
  29.  
  30. public static void main(String[] args) {
  31. Main prog = new Main();
  32. IndirectReference<Enum> ref = new IndirectReference(Enum.E1);
  33. prog.foo(ref);
  34. System.out.println("Before: " + prog.get());
  35. ref.set(Enum.E2);
  36. System.out.println("After: " + prog.get());
  37. }
  38. }
  39.  
Success #stdin #stdout 0.06s 380160KB
stdin
Standard input is empty
stdout
Before: E1
After: E2