最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

求幫助,編譯時不報錯。運行時報錯。

求幫助,編譯時不報錯。運行時報錯。

念瑤 2015-07-15 16:18:50
package n;public interface Comparable<Student> {?? public int compareTo(Student s);}package n;import java.util.Set;import java.util.TreeSet;public class Student implements Comparable<Student> {?????? int id;?????? String name;?????? public Student(int id, String name){?? ??? ??? this.id = id;?? ??? ??? this.name = name;?????? }?????? public int compareTo(Student s){?? ??? ??? if(this.id < s.id) return -1;?? ??? ??? else if(this.id > s.id) return 1;?? ??? ??? else return 0;?????? }?????? public String toString(){?? ??? ??? return "<" + this.id + "." + this.name + ">";?????? }?? ?public static void main(String[] args) {?? ??? ?// TODO 自動生成的方法存根??????? Student[] stud = new Student[]{?????? ??? ??? ?new Student(1002, "張三"),?????? ??? ??? ?new Student(1003, "李四"),?????? ??? ??? ?new Student(1001, "王五")??????? };??????? Set<Student> ts = new TreeSet<Student>();??????? for(int i = 0; i < stud.length; i ++)?????? ??? ?ts.add(stud[i]);??????????? System.out.println(ts);?? ?}?? }
查看完整描述

1 回答

?
此用戶略帥

TA貢獻4條經(jīng)驗 獲得超1個贊

報什么錯?

查看完整回答
反對 回復 2015-07-17
  • 念瑤
    念瑤
    Exception in thread "main" java.lang.ClassCastException: n.Student cannot be cast to java.lang.Comparable at java.util.TreeMap.compare(TreeMap.java:1188) at java.util.TreeMap.put(TreeMap.java:531) at java.util.TreeSet.add(TreeSet.java:255) at n.Student.main(Student.java:30)
  • 1 回答
  • 0 關(guān)注
  • 1722 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號