簡體   English   中英

JDI:如何迭代 HashMap

[英]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? 如何使用 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?

假設 hashMap 是 HashMap<T, V> 類型。

mapConfig.forEach((k, v) -> {

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM