我需要查看我的hashMap键和值以检查其是否正常运行。但是我收到以下几行错误:

Iterator iterator =  myHashMap.keySet().iterator();
    Flows flows = new Flows();
    while(iterator.hasNext()){
        Object key = iterator.next();
        Object value = myHashMap.get(key); // <--
        //here is the error.  suspicious call to java.util.Map.get
        //expected type Flows, actual type object

        System.out.println(key+" "+value);
    }


我的键是Flows的类型,我的值是FlowsStatics。

最佳答案

如果将Map声明为Map<Flows, FlowsStatics>,则迭代器将自动返回Flow类的对象,您确实应该这样做:

while(iterator.hasNext()){
    Flows key = iterator.next();
    FlowsStatics value = myHashMap.get(key);

09-26 09:57