import java.util.*;class Z implements Comparable{??? int age;?? ?public Z(int age){?? ??? ?this.age=age;?? ?}?? ?//?? ?public boolean equals(Object obj){?? ??? ?return true;?? ?}?? ?//?? ?public int compareTo(Object obj){?? ??? ?return 1;?? ?}?? ?public class TressSetTest2{?? ?? //下面代碼在編譯時(shí)出現(xiàn)?? “錯(cuò)誤: 內(nèi)部類Z.TressSetTest2中的靜態(tài)聲明非法,???????????????????????????????????????????????? public static void main(String[] args){???????????????????????????????????????????????? public static void main(String[] args){”????? 的錯(cuò)誤,當(dāng)我把“static”刪除時(shí),又出現(xiàn)“錯(cuò)誤: 找不到或無(wú)法加載主類 TreeSetTest2”? ? ? ? public static void main(String[] args){?? ?? ??? ??? ?TreeSet set=new TreeSet();?? ??? ??? ?Z z1=new Z(6);?? ??? ??? ?set.add(z1);?? ??? ??? ?//?? ??? ??? ?System.out.println(set.add(z1));?? ??? ??? ?//?? ??? ??? ?System.out.println(set);?? ??? ??? ?//?? ??? ??? ?((Z)(set.first())).age=9;?? ??? ??? ?//?? ??? ??? ?System.out.println(((Z)(set.last())).age);?? ??? ?}?? ?}}
3 回答

果果愛吃蘋果
TA貢獻(xiàn)50條經(jīng)驗(yàn) 獲得超20個(gè)贊
代碼未做任何改動(dòng),就是復(fù)制你的代碼,要不你仔細(xì)檢查一下語(yǔ)法?或者用一下開發(fā)工具
添加回答
舉報(bào)
0/150
提交
取消