Generic methods in Java

static <T> void swap(T[] a, T[] b) {
    T tmp = a[0];
    a[0] = b[0];
    b[0] = tmp;
}

Integer[] n1 = {5};
Integer[] n2 = {7};
swap(n1n2);
//n1[0] is 7 and n2[0] is 5

String[] s1 = {"cat"};
String[] s2 = {"dog"};
swap(s1s2);
//s1[0] is "dog" and s2[0] is "cat"