类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);请问下这样写哪里有问题?要怎么写
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);请问下这样写哪里有问题?要怎么写
KerryPagination kerry = new KerryPagination(gg);
需要的是List里包含的是<T>的数组啊,你就得传个包含T的过去
public class KerryPagination{
private List listShow = new ArrayList();
public KerryPagination(List gg) {
this.listShow = gg ;
}
}
这么写你传什么都可以了
private List<?> listShow = new ArrayList<?>();
public KerryPagination(List<T> gg) {
this.listShow = gg ;
}
}
private List<?> listShow = new ArrayList<?>();
public KerryPagination(List<T> gg) {
this.listShow = gg ;
}
}
这样写
我假如要传个 list<User> 也是可以的吗?
KerryPagination kerry = new KerryPagination<TGameList>(gg);
这样写会报错的
这样写会报错的
private List<?> listShow ;或者private List<?> listShow = null;
private List<T> listShow=new ArrayList<T>() ;
public KerryPagination(List<T> gg) {
this.listShow = gg ;
}
}我试了一下 这样是可以的,你可以看看API中,泛型类都是怎么写的。
Comparable 和comparator都比较有代表性
public <T> KerryPagination(List<T> gg) {
this.listShow = gg ;
}