English 中文(简体)
• 如何将一台推器推向一台散射器 地图
原标题:how to call an Iterator over a hashMap

i 需要看到我的蒸气钥匙和价值,以便检查它是否正常工作。 但对以下各行将产生错误:

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);
    }

我的关键是流动类型,我的价值是流动统计。

最佳回答

如果您宣布“<>Map为Map<Flows, flowssStatics>,你将自动退回班流物。

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

您是否用一种通用的类型宣布了我的HashMap:例如HashimMap<Flows, 流程统计学;?

如果是的话,你应在整个过程中使用通用物:

Iterator<Flows> iterator =  myHashMap.keySet().iterator();
while(iterator.hasNext()){
    Flows key = iterator.next();
    FlowStatics value = myHashMap.get(key); // <--

甚至:

for(Flows key: myHashMap.keySet().iterator()){
    FlowStatics value = myHashMap.get(key);

甚至:

for(Map.Entry<Flows, FlowStatics> entry: myHashMap.entrySet().iterator()){
    Flows key = entry.getKey();
    FlowStatics value = entry.getValue();




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签