import org.apache.catalina.tribes.group.interceptors.TwoPhaseCommitInterceptor.MapEntry;
class Student implements Comparable<Student>
{
private String name;
private int age;
Student(String name,int age)
{
this.name = name;
this.age = age;
}
public int compareTo(Student s)
{
int num = this.name.compareTo(s.name);
if(num==0)
{
return this.age-s.age;
}
return num;
}
public int hashCode()
{
//System.out.println(this.name+"^^hashCode^^"+this.age);
return name.hashCode()+age*34;
}
public boolean equals(Object obj)
{
if(!(obj instanceof Student))
throw new ClassCastException("类型不匹配");
Student s = (Student)obj;
System.out.println(this.name+"^^^^equals^^^"+s.name);
return this.name.equals(s.name)&&this.age==s.age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public String toString()
{
return this.getName()+":"+this.getAge();
}
}
public class MapTest
{
public static void main(String[] arge)
{
HashMap<Student,String> hm = new HashMap<Student,String>();