나는 HashMap을 가지고있다. 객체에는 이름, 주소, 전자 메일과 같은 정보가 들어 있습니다. HashMap을 반복 할 수 있지만 Object에서 값을 가져올 수 없습니다. 아무도 내게 이것을 할 수있는 적절한 방법을 보여줄 수 있다면 내 코드는 여기있다.Java의 hashmap에서 내부 객체의 값을 가져 오는 방법은 무엇입니까?
public void getData(){
// hashmap is records<key, Object>
// Object contains properties name, address, email
Iterator it = records.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object val = entry.getValue();
// this gets me through hashmap
// how do I get name, address and email from object?
}
}
현대 코드에서는 제네릭없이 'HashMap'을 사용하면 안됩니다. –