您的位置:首页 > 编程语言 > Java开发

在eclipse中运行上面程序总是提示Multiple markers at this line

2015-10-30 00:00 906 查看
摘要: class Student implements Comparable,Comparator那一行报错,Multiple markers at this line
- Comparator is a raw type. References to generic type Comparator<T> should be
parameterized
- The type Student must implement the inherited abstract method
Comparable.compareTo(Object)
- Comparable is a ra...

package test1; import java.util.*; public class Work1 { /** *
@param args */ public static void main(String[] args) { TreeSet ts=new TreeSet(new Student.StudentComparator()); ts.add(new Student(301,"张三")); ts.add(new Student(201,"李二")); ts.add(new Student(101,"王五")); ts.add(new Student(101,"穷一")); Iterator it=ts.iterator(); while(it.hasNext()){ System.out.println(it.next()); } } } class Student implements Comparable,Comparator{ private int num; private String name; public Student(int num,String name){ this.num=num; this.name=name; } public int comparaTo(Object o){ Student st=(Student)o; int result; result=num>st.num?1:(num==st.num?0:-1); return result; } public int compare(Object o1,Object o2){ Student st1=(Student)o1; Student st2=(Student)o2; return st1.name.compareTo(st2.name); } public String toString(){ return "num="+num+";name="+name; } public static class StudentComparator implements Comparator{ public int compare(Object o1,Object o2){ Student st1=(Student)o1; Student st2=(Student)o2; int result; result=st1.num>st2.num?1:(st1.num==st2.num?0:-1); if(result==0) { result=st1.name.compareTo(st2.name); } return result; } } }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: