[英]JDI:How to iterate over HashMap
I get through JDI to get com.sun.jdi.ObjectReference
is type java.util.HashMap
,then i get filed value "entrySet",why it is always null? I get through JDI to get com.sun.jdi.ObjectReference
is type java.util.HashMap
,then i get filed value "entrySet",why it is always null? How can i iterate over HashMap keyValues with java debug api?如何使用 java 调试 api 迭代 HashMap 键值?
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);
}
}
}
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?
Assuming hashMap is of type HashMap<T, V>.假设 hashMap 是 HashMap<T, V> 类型。
mapConfig.forEach((k, v) -> {
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.