关于java泛型的,请各位大侠帮忙看看这段代码为什么报错啊????
@Test//测试数据交换publicvoidTestswap(){int[]arry=newint[9];swapt(arry,0,2);}public<E>Eswap...
@Test //测试数据交换
public void Testswap(){
int[] arry = new int[9];
swapt(arry, 0, 2);
}
public <E> E swapt(E arry[],int index1,int index2){
E Template = arry[index1];
arry[index1] = arry[index2];
arry[index2] = Template;
return (E) arry;
} 展开
public void Testswap(){
int[] arry = new int[9];
swapt(arry, 0, 2);
}
public <E> E swapt(E arry[],int index1,int index2){
E Template = arry[index1];
arry[index1] = arry[index2];
arry[index2] = Template;
return (E) arry;
} 展开
2个回答
展开全部
public void Testswap() {
Integer[] arry = new Integer[9];
swapt(arry, 0, 2);
}
public <E> E swapt(E arry[], int index1, int index2) {
E Template = arry[index1];
arry[index1] = arry[index2];
arry[index2] = Template;
return (E) arry;
}
看下这个,你的数组类型不能直接用int,改为Integer就没事了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询