public class AWrongSwap {
    public static void wrongSwapInts(int n1, int n2) {
        int aux = n1;
        n1 = n2;
        n2 = aux;
    }
    // Perque n1 i n2 es passen per valor
    public static void wrongSwapIntegers(Integer o1, Integer o2) {
        Integer aux = o1;
        o1 = o2;
        o2 = aux;
    }
    // Cos wrapper objects are immutable (just like String)
    public static void alsoWrongSwapIntegers(Integer o1, Integer o2) {
        int aux = o1;
        int n1 = o2;
        int n2 = aux;
        o1 = new Integer(n1);
        o2 = new Integer(n2);
    }
    // And, cos references are passed by value
    // Como si estubiera pasando el numero de objeto
    public static void main(String[] args) {
        int n1 = 2 , n2 = 3;
        Integer o1 = new Integer(7); // unnecessary boxing
        Integer o2 = -1; // new Integer(-1) implicito
        System.out.println("n1 = " + n1 + ", n2 = " + n2);
        wrongSwapInts(n1, n2);
        System.out.println("n1 = " + n1 + ", n2 = " + n2);
        System.out.println("o1 = " + o1 + ", o2 = " + o2);
        wrongSwapIntegers(o1, o2);
        System.out.println("o1 = " + o1 + ", o2 = " + o2);
        System.out.println("o1 = " + o1 + ", o2 = " + o2);
        alsoWrongSwapIntegers(o1, o2);
        System.out.println("o1 = " + o1 + ", o2 = " + o2);
    }
}
