在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; } } }
- 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; } } }
相关文章推荐
- 关于Hibernate执行查询后会引发update操作的解决方法
- MyBatis整合Spring的实现(15)
- MyBatis整合Spring的实现(16)
- MyBatis整合Spring的实现(17)
- MyBatis整合Spring的实现(18)
- java 堆与栈的区别
- java join 多线程顺序执行
- Spring 事务管理探究
- java阿拉伯数字转换成中文数字
- java判断字符串所属的编码类型
- Java ConcurrentModificationException异常原因和解决方法
- 开更C博
- Spring Web mvc Maven实现文件上传
- 从头认识java-6.2 继承(Generalization)(2)
- 从头认识java-6.2 继承(Generalization)(2)
- Java反射基础(三)--Methods对象的使用
- java.util.logging.Logger使用详解
- Spring3:AOP
- Java多线程
- Java 异常处理