A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 一帆风顺 中级黑马   /  2012-12-25 14:08  /  1728 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 王博 于 2012-12-25 14:17 编辑

用myeclipse编写完代码编译能通过,也能运行,可是文件前面为什么会有个小叹号啊。。。加了其他文件又变成叉了。。。试了怎么改代码都没办法
下面附图:

下面附上我的代码
package com.itheima
import java.util.*;
class Test
{
    public static void main(String[] args)
    {
       //定义一个TreeSet集合
       TreeSet<Student> ts = new TreeSet<Student>();
       //添加元素
       ts.add(new Student("heima01",22,89));   
       ts.add(new Student("heima02",20,90));
       ts.add(new Student("heima03",19,56));
       ts.add(new Student("heima04",19,77));
       ts.add(new Student("heima05",20,65));

       //迭代器打印元素
       Iterator<Student> it = ts.iterator();   
       while(it.hasNext())
       {
           Student stu = (Student)it.next();
           System.out.println("姓名是"+stu.getName()+",年龄:"+stu.getAge()+",成绩:"+stu.getScore());
       }
    }
}
class Student implements Comparable    //错误应该是这里吧
{
    private String name;
    private int age;
    private double score;
    Student(String name,int age,double score)
    {
       this.name = name;
       this.age = age;
       this.score = score;
    }
    public int compareTo(Object obj)
    {
       if(!(obj instanceof Student))
           throw new RuntimeException("不是学生对象");
       Student s = (Student)obj;
       if(this.score<s.score)         
           return 1;
       if(this.score==s.score)
       {
           return this.name.compareTo(s.name);
       }
       return -1;

    }
    public String getName()
    {
       return name;
    }
    public int getAge()
    {
       return age;
    }
    public double getScore()
    {
       return score;
    }
}

360桌面截图6.jpg (72.23 KB, 下载次数: 23)

360桌面截图6.jpg

评分

参与人数 1技术分 +1 收起 理由
奋斗的青春 + 1 赞一个!

查看全部评分

4 个回复

倒序浏览
没加泛型,Comparable<Student>
回复 使用道具 举报
亲,你的泛型呢。。。。。。。Comparable<Student>
回复 使用道具 举报
是就在Comparable上加泛型么,我加过试了啊,怎么结果直接出现叉了?是我加的不对么??
回复 使用道具 举报
如果只是不想出现叹号的话,使用注释就好@SuppressWarnings("rawtypes")
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马