import java.util.*;
import com.bruceeckel.util.*;
class E_13_2 implements Comparator
{
private String s1;
private String s2;
private E_13_2 e;
E_13_2(String s1,String s2){
this.s1=s1;
this.s2=s2;
}
public boolean equals(Object o){
return (o instanceof E_13_2)&&(s2==((E_13_2)o).s2);
}
public int compare(Object o1,Object o2){
String s3=((E_13_2)o1).s2, s4=((E_13_2)o2).s2;
return e.compare(s3,s4);
}
public String toString(){
return "[s1:"+s1+"<>s2:"+s2+"]";
}
public static Arrays2.RandStringGenerator gen=
new Arrays2.RandStringGenerator(8);
public static Generator generator(){
return new Generator(){
public Object next(){
return new E_13_2((String)gen.next(),(String)gen.next());
}
};
}
}
public class E13Test
{
public static void main(String args[]){
E_13_2[] e13 = new E_13_2[10];
Arrays2.fill(e13,E_13_2.generator());
Arrays2.print("before sort() =>",e13);
Arrays.sort(e13);
Arrays2.print("after sort() =>",e13);
}
}
+-----------output----------------+
before sort() => ([s1:dmOmrMCG<>s2:tuMsnVcf], [s1:CbWECTsI<>s2:AzTHfIcq], [s1:QASdXyRN<>s2:ydUhgXBj], [s1:jWLThZNP<>s2:pJnyGKiG], [s1:aqXwNAWq<>s2:dNmVZbuQ], [s1:KxKLcEQd<>s2:VIiAZiIt], [s1:ycDvsmYR<>s2:sBMFozNq], [s1:fbfcKGnd<>s2:tGEchRKv], [s1:wvQmPgJh<>s2:fJEDWkcG], [s1:FfaksBZv<>s2:lnhSLecY])
java.lang.ClassCastException
at java.util.Arrays.mergeSort(Arrays.java:1152)
at java.util.Arrays.mergeSort(Arrays.java:1163)
at java.util.Arrays.sort(Arrays.java:1079)
at E13Test.main(E13Test.java:38)
Exception in thread "main"
输出完成 (耗时 0 秒) - 正常终止
我是哪里出错了,该怎样改啊?