Java比较器-函数访问
我有课:Java比较器-函数访问,java,comparator,Java,Comparator,我有课: public class GridResponse<V> { public void setPage(int page) { this.page = page; } } 公共类GridResponse{ 公共无效设置页(整版页){ this.page=page; } } 和类实现的比较器: public class GridComparator<GridResponse> implements Comparator<
public class GridResponse<V> {
public void setPage(int page) {
this.page = page;
}
}
公共类GridResponse{
公共无效设置页(整版页){
this.page=page;
}
}
和类实现的比较器:
public class GridComparator<GridResponse> implements Comparator<GridResponse> {
@Override
public int compare(GridResponse o1, GridResponse o2) {
o1.setPage = '1';
return 0;
}
}
公共类GridComparator实现Comparator{
@凌驾
公共整数比较(GridResponse o1、GridResponse o2){
o1.setPage='1';
返回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;
}
}
公共类GridComparator实现Comparator{
@凌驾
公共整数比较(GridResponse o1、GridResponse o2){
o1.设置页(1);
返回0;
}
}
您是否可以添加一个代码快照,以显示您正在尝试执行但失败的操作?(显示您无法访问的内容)。另外,GridComparator
是一个内部类吗?从你发布的代码来看,唯一的问题似乎是,你使用的是你的类的非泛型版本,而你的类GridResponse
是泛型的。我更新了我的帖子,我没有写o1.setPage,因为我有:setPage无法解析或不是字段GridResponse
中没有成员page
。另外,o1.setPage='1'
不是有效的Java代码,因为setPage()
是一个方法而不是公共成员…@brimborium。。嗯,o1.setPage='1'代码>,是有效的Java代码。只是,它在这里是无效的。