2黑马币 
- public class Test1 {
 
 -         @Test
 
 -         public void test(){
 
 -                 int arr[] = {1,2,3,4,5,6,7,8,9};
 
 -                 reverse(arr);
 
 -         }
 
  
-         
 
 -         
 
 -         //编写一个泛型方法,实现数组反转
 
 -         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--;
 
 -                 }
 
 -         }
 
 - }
 
 
  复制代码 
 
 |   
 
 
最佳答案
查看完整内容 
int改成Integer,泛型是针对对象的,不是针对基本数据类型,需要自动提升一下 
 
 
 
        
 
    
    
    
     
 
 |