我通过JDI获得com.sun.jdi.ObjectReference是java.util.HashMap类型,然后得到文件值"entrySet“,为什么它总是为null?如何使用java调试api在HashMap keyValues上迭代?
public static void displayVariables(LocatableEvent event) throws IncompatibleThreadStateException, AbsentInformationException {
StackFrame stackFrame = event.thread().frame(0);
for (LocalVariable visibleVariable : stackFrame.visibleVariables()) {
Value value = stackFrame.getValue(visibleVariable);
if(value instanceof ObjectReference){
ObjectReference objectReference = (ObjectReference) value;//is type java.util.HashMap
Field entrySet = objectReference.referenceType().fieldByName("entrySet");// is java.util.HashMap.entrySet
Value entrySetValue = objectReference.getValue(entrySet);// is null
System.out.println(entrySet);
}
}
}

发布于 2021-12-13 04:36:34
for (T key : hashMap.keySet()) {
V value = hashMap.get(key);
// rest of your code here
} // Can you get to where you need to go from here?假设hashMap是HashMap。
发布于 2021-12-13 04:49:23
mapConfig.forEach((k, v) -> {
});https://stackoverflow.com/questions/70329774
复制相似问题