Created
November 8, 2014 20:43
-
-
Save Karasiq/12e81a61b162adb25dc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
public class Main { | |
public static void swap(Object a, Object b) { | |
try { | |
java.lang.reflect.Field value = a.getClass().getDeclaredField("value"); | |
value.setAccessible(true); | |
Object tmp = value.get(a); | |
value.set(a, value.get(b)); | |
value.set(b, tmp); | |
} catch (Exception e) {} | |
} | |
public static void main(String[] args) { | |
String first = "first"; | |
String second = "second"; | |
System.out.println(first+" "+second); | |
swap(first, second); | |
System.out.println(first+" "+second); | |
System.out.println(); | |
Integer x = 1; | |
Integer y = 2; | |
System.out.println(x+" "+y); | |
swap(x, y); | |
System.out.println(x+" "+y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment