fork(3) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. public class Main {
  6. public static void swap(Object a, Object b) {
  7. try {
  8. java.lang.reflect.Field value = a.getClass().getDeclaredField("value");
  9. value.setAccessible(true);
  10. Object tmp = value.get(a);
  11. value.set(a, value.get(b));
  12. value.set(b, tmp);
  13. } catch (Exception e) {}
  14. }
  15.  
  16. public static void main(String[] args) {
  17. String first = "first";
  18. String second = "second";
  19. System.out.println(first+" "+second);
  20. swap(first, second);
  21. System.out.println(first+" "+second);
  22.  
  23. System.out.println();
  24.  
  25. Integer x = 1;
  26. Integer y = 2;
  27. System.out.println(x+" "+y);
  28. swap(x, y);
  29. System.out.println(x+" "+y);
  30. }
  31. }
  32.  
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
first second
second first

1 2
2 1