0

我有课:

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 中的功能?为什么?

4

1 回答 1

2

该类GridComparator根本不应该是通用的,它是特定于GridResponse该类的。

public class GridComparator implements Comparator<GridResponse<Integer>> {
    @Override
    public int compare(GridResponse<Integer> o1, GridResponse<Integer> o2) {
        o1.setPage(1);
        return 0;
    }
}
于 2012-12-03T12:00:36.623 回答