1 import org.junit.Test;
2
3 public class ArrReserve {
4 @Test
5 public void test() {
6 // String[] arr = {"1","2","3","4","5","6"};
7 Integer[] arr = { 1, 2, 3 };//如果把Integer改成int,会编译失败,因为自定义泛型不能是基本数据类型?!
8 reserve(arr);
9 }
10
11 public <T> void reserve(T arr[]) {
12 int start = 0;
13 int end = arr.length - 1;
14
15 while (start < end) {
16 T t = arr[start];
17 arr[start] = arr[end];
18 arr[end] = t;
19 start++;
20 end--;
21 }
22 for (T temp : arr) {
23 System.out.println(temp);
24
25 }
26 }
27
28 }