- public static void main(String[] args) {
- Integer a = 9, b = 8;
- swap(b,a);
- System.out.println(a);
- System.out.println(b);
- }
-
- private static void swap(Integer a, Integer b) {
- try {
- Field value = a.getClass().getDeclaredField("value");
- value.setAccessible(true);
- int tmpa = (int) value.get(a);
- value.set(a, (int)value.getInt(b));
- value.set(b, tmpa);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
复制代码
我加过两个中间变量,一句一打印,一句一断点,swap(a, b) 一直是 8, 8, swap(b, a) 就是 9, 9, 就是换不过来,实在是想不通 |
|