日期:2014-05-20  浏览次数:20727 次

自定义泛型调用出错什么意思?
Java code

public class Demo1 {
    
    public <T> void swap(T arr[], int pos1, int pos2) {
        T temp = arr[pos1];
        arr[pos1] = arr[pos2];
        arr[pos2] = temp;
    }
}



Java code

public class TestDemo {

    @Test
    public void test1() {
        int intArr[] = new int[] { 12, 13, 15, 14 };

        Demo1 d = new Demo1();

        d.swap(intArr, 1, 2);
    }
}


这个调用 的时候报错说
The method swap(T[], int, int) in the type Demo1 is not applicable for the arguments (int[], int, int)

这个什么意思?

------解决方案--------------------
泛型不支持原始类型