Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 java.lang.ClassCastException
AchillesA

  very com



发贴: 35
积分: 0
于 2004-09-07 16:34 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

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 秒) - 正常终止

我是哪里出错了,该怎样改啊?




[转帖]面向对象的思维方法

话题树型展开
人气 标题 作者 字数 发贴时间
6215 java.lang.ClassCastException AchillesA 1642 2004-09-07 16:34
4667 Re:java.lang.ClassCastException cxp108 320 2004-09-07 17:10
4472 Re:java.lang.ClassCastException AchillesA 243 2004-09-08 20:34

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923