关于泛型。
类KerryPagination:
public class KerryPagination{
private List<T> listShow = new ArrayList<T>();
public KerryPagination(List<T> gg) {
this.listShow = gg ;
}
}
在类PaginationBean中实例化KerryPagination:
List<TGameList> gg = new ArrayList<TGameList>();
KerryPagination kerry = new KerryPagination(gg);
请问下这样写哪里有问题?要怎么写
[解决办法]
List<T> gg = new ArrayList<T>();
KerryPagination kerry = new KerryPagination(gg);
需要的是List里包含的是<T>的数组啊,你就得传个包含T的过去
[解决办法]
那你就别用泛型了,有必要的话根据需求强制转换
[解决办法]
public class KerryPagination{
private List<?> listShow = new ArrayList<?>();
public KerryPagination(List<T> gg) {
this.listShow = gg ;
}
}
[解决办法]
public class KerryPagination<T>{
private List<?> listShow = new ArrayList<?>();
public KerryPagination(List<T> gg) {
this.listShow = gg ;
}
}
这样写
[解决办法]
List<TGameList> gg = new ArrayList<TGameList>();
KerryPagination kerry = new KerryPagination<TGameList>(gg);
[解决办法]