public static <T> void swap(T[] t , int a , int b){
T temp = t[a];
t[a] = t[b];
t[b] = temp;
}
@Test
public void test(){
String[] a = new String[]{"sd","sdz","asa"};
//int[] a = {1,2,3,4};
//泛型只能表示引用类型
//int[] a = new int[]{1,2,3,4,5};
swap(a,1,2);
}
注意:泛型只支持引用类型,不支持基本数据类型