package org.set;
public class Person implements Comparable<Person> {
private String name;
private int age;
public Person(String name, int age) {
super();
this.name = name;
this.age = age;
}
@Override
public String toString() {
// TODO 自动生成的方法存根
return "姓名:"+this.name+",年龄:"+this.age;
}
@Override
public int compareTo(Person per) {
// TODO 自动生成的方法存根
if(this.age>per.age){
return 1;
}else if(this.age<per.age){
return -1;
}else{
return 0;
}
}
}
public class Person implements Comparable<Person> {
private String name;
private int age;
public Person(String name, int age) {
super();
this.name = name;
this.age = age;
}
@Override
public String toString() {
// TODO 自动生成的方法存根
return "姓名:"+this.name+",年龄:"+this.age;
}
@Override
public int compareTo(Person per) {
// TODO 自动生成的方法存根
if(this.age>per.age){
return 1;
}else if(this.age<per.age){
return -1;
}else{
return 0;
}
}
}