第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

求幫助,編譯時(shí)不報(bào)錯(cuò)。運(yùn)行時(shí)報(bào)錯(cuò)。

求幫助,編譯時(shí)不報(bào)錯(cuò)。運(yùn)行時(shí)報(bào)錯(cuò)。

念瑤 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 自動(dòng)生成的方法存根??????? 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 回答

?
此用戶(hù)略帥

TA貢獻(xiàn)4條經(jīng)驗(yàn) 獲得超1個(gè)贊

報(bào)什么錯(cuò)?

查看完整回答
反對(duì) 回復(fù) 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)注
  • 1712 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

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