如题:代码如下,错误已标出
package manegement;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
//增加员工信息
public class Add {
//hashmap 存放员工信息
HashMap hm = new HashMap<Integer, Object>();
Employee emp = new Employee();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String temp = new String();
public void main() {
AddEmp();
System.out.println("通过Map.entrySet遍历key和value");
/**
* Type mismatch: cannot convert from element type Object to Map.Entry<String,String>
* line:28
*/
for (HashMap.Entry<String, String> entry : hm.entrySet()) {
System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
}
}
public void AddEmp() {
System.out.println("员工ID:");
try {
temp = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
emp.setEmpID(Integer.parseInt(temp));
System.out.println("员工姓名:");
try {
temp = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
emp.setName(temp);
System.out.println("员工工资:");
try {
temp = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
emp.setSalay(Float.parseFloat(temp));
//添加员工信息到HashMap
hm.put(emp.getEmpID(), emp);
}
}