java-learner
java-learner

Reputation: 79

statement not compiling

I have a method from decompiled code that i am trying to run and understand. The 5 line does not compile and i get an error saying incompatible types required: java util.Hashmap found: java.lang.String.

private void resetFieldModel(HashMap<String, Integer> to_use_map)
{
    this.current_field_model.removeAllElements();
    Set temp_set = to_use_map.keySet();

    for (String s : temp_set)
    {
        this.current_field_model.addElement(s);
    }
}

Upvotes: 0

Views: 73

Answers (2)

Venkata Krishna
Venkata Krishna

Reputation: 15112

You must iterate through the temp_set which must of Set<String> type(in your code). The idea is that each element in temp_set is of type String

Upvotes: 0

BalusC
BalusC

Reputation: 1108782

You need to type-parameterize the temp_set.

Set<String> temp_set = to_use_map.keySet();

See also:

Upvotes: 5

Related Questions