- public class Test1 {
- @Test
- public void test(){
- int arr[] = {1,2,3,4,5,6,7,8,9};
- reverse(arr);
- }
-
- public <T> void a(T t){}
- //编写一个泛型方法,实现数组指定位置上的数进行交换
- public <T> void swap(T arr[],int pos1,int pos2){
-
- T temp = arr[pos1];
- arr[pos1]=arr[pos2];
- arr[pos2]=temp;
- }
-
- //编写一个泛型方法,实现数组反转
- public <T> void reverse(T arr[]){
- int start = 0;
- int end = arr.length-1;
- while(start<end){
-
- T temp = arr[start];
- arr[start] = arr[end];
- arr[end] = temp;
-
- start++;
- end--;
- }
- }
- }
复制代码
请问这代码调用为什么不行??? |
|