HashMap 的值如何变化?

How the value of HashMap changes?

我使用 XStream 库解析了一些 xml 文件。结果是每个文件的映射。当我调试时,结果映射正是我要找的,但是当我转到下一行时,映射的值突然发生了变化!但是它不会进入 "for" 循环中的下一轮,它包含下一个文件的信息。什么会导致它?

public class Debug {
public String path = "E:\Projects\svn\FANRPProduction\WMS\src\main\resources\wms\bpmn\bp";
public XStream xStream;
public Map<String, List<CallActivity>> bpTpMap;

public void findBPandTP() throws IOException {
    File root = new File(path);
    File[] xmlFiles = FindAllXMLFiles.recursive(root);

    bpTpMap=new HashMap<String, List<CallActivity>>();
    for (File xml : xmlFiles) {
        if (xml != null) {
            xStream = new XStream(new StaxDriver());
            xStream.alias("definitions", CallActivity.class);
            xStream.registerConverter(new CallActivityConverter());
            bpTpMap = (Map) xStream.fromXML(xml);//Here I get correct information. For example "WMS_RBP_OutgoingWeighing"
            List<String> bpList = new ArrayList<String>(bpTpMap.keySet()); //Here I see the name of the next file in the path in bpTpMap, which is "WMS_BP_WeighingConfiguration"
        }
    }
}

}

我建议您使用以下方法进行调试:

bpTpMap = (Map) xStream.fromXML(xml);//Here I get correct information. For example "WMS_RBP_OutgoingWeighing"

System.out.println(bpTpMap.size());
Set<String> setOfKeys = bpTpMap.keySet();
System.out.println("Initial value of keys:"+bpTpMap);//Here you would see any extra values if the map has it