有个错误,请帮改正
//HashtableTest.java,程序启动文件,运行时报错,希望得到指点,谢谢import java.util.*;
class HashtableTest {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: Add your code here
Hashtable m =new Hashtable();
m.put(new MyKey("zhangsan","18"),new Integer(1));
m.put(new MyKey("lisi","15"),new Integer(2));
m.put(new MyKey("wangwu","20"),new Integer(3));
Enumeration e=m.keys();
while(e.hasMoreElements())
{
MyKey key=(MyKey)e.nextElement();
System.out.println(key.toString()+"="+m.get(key));
}
}
}
//MyKey.java
public class MyKey {
private String name = null;
private int age = 0;
/**
* Method MyKey
*
*
*/
public MyKey(String name ,int age) {
// TODO: Add your code here
this.name=name;
this.age=age;
}
/**
* Method equals
*
*
* @return
*
*/
public boolean equals(Object obj) {
// TODO: Add your code here
if(obj instanceof MyKey)
{
MyKey mk =(MyKey)obj;
if(this.name.equals(mk.name)&&(this.age==mk.age))
return true;
else
return false;
}
else
{
return false;
}
}
/**
* Method hashCode
*
*
* @return
*
*/
public int hashCode() {
// TODO: Add your code here
return name.hashCode()+age;
}
/**
* Method toString
*
*
* @return
*
*/
public String toString() {
// TODO: Add your code here
return name + "," + age;
}
}