我有课:
public class GridResponse<V> {
public void setPage(int page) {
this.page = page;
}
}
和类实现的比较器:
public class GridComparator<GridResponse> implements Comparator<GridResponse> {
@Override
public int compare(GridResponse o1, GridResponse o2) {
o1.setPage = '1';
return 0;
}
}
GridComparator类有什么问题,因为我无法访问GridResponse中的函数?为什么?
最佳答案
GridComparator
类根本不应该是泛型的,它是GridResponse
类所特有的。
public class GridComparator implements Comparator<GridResponse<Integer>> {
@Override
public int compare(GridResponse<Integer> o1, GridResponse<Integer> o2) {
o1.setPage(1);
return 0;
}
}