Name: Anonymous 2016-03-17 1:17
People told me it can't be done. However I created the impossible, java int swap function.
You C++/C# elitists can't mock my pass-by-value only language anymore
import java.lang.reflect.*;
class IntSwap
{
static char n[];
static {
try{
Field field = Integer.class.getDeclaredFields()[3];
field.setAccessible(true);
n = (char[])field.get(1);
} catch(Exception e){}
}
public static void swap(int a, int b){
char t = n[a];
n[a] = n[b];
n[b] = t;
}
public static void main(String args[]) throws Exception {
int a = 1;
int b = 3;
int c = 7;
System.out.format("a = %d, b = %d, c = %d\n", a, b, c);
swap(a, b);
System.out.format("a = %d, b = %d, c = %d\n", a, b, c);
swap(b, c);
System.out.format("a = %d, b = %d, c = %d\n", a, b, c);
swap(a, c);
System.out.format("a = %d, b = %d, c = %d\n", a, b, c);
}
}
You C++/C# elitists can't mock my pass-by-value only language anymore