大家来看看啊,为什么说找不到符号
import java.util.*;
class Test{
public static void main(String[] args){
ArrayList <Object> al=new ArrayList <Object> ();
al.add(new A(3,4));
al.add(new A(4,6));
al.add(new A(3,4));
System.out.println(al);
Collections.sort(al,new B());
}
}
class A {
int x,y;
A(int x,int y){
this.x=x;
this.y=y;
}
public String toString(){
return x+ " "+y;
}
}
class B implements Comparator{
public int compare(Object o1,Object o2){
A a1=(A)o1;
A a2=(A)o2;
return al.x> a2.x?0:1;//编译时说找不到符号,该怎么改呢,谢谢了啊
}
}
------解决方案--------------------我想问问楼主al.x> a2.x是啥意思?貌似A类里没有静态变量x吧。
------解决方案--------------------ArrayList al = new ArrayList();
ArrayList al = new ArrayList();
-----------------------
return al.x> a2.x?0:1;
||
return a1.x> a2.x?0:1;
1和l是不一样地
------解决方案--------------------Little_qd(沉淀思想) ( ) 信誉:99 Blog
强!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------解决方案--------------------return al.x> a2.x?0:1;//a1写成了aL????
------解决方案--------------------无语中……