Forced to iterate over Collection<String> using Object?

66 views Asked by At

All of a sudden, 2017.1.5 does not allow me to iterate over a Collection<String> with a forach and a String variable.

The simple piece of code:

for (String methodPath : methodsService.getMethodPaths()) {
    // ....
}

where

private Map<String, MethodMeta> methods = new HashMap<>();

public Collection<String> getMethodPaths() {
    return this.methods.keySet();
}

is marked as error with the suggestion to change the variable methodPath from String to Object.

At the beginning, I thought the IDE was just indexing and the error for some later-edited code was still appearing, which wouldn't bother me as much, but it actually does not compile the project:

Compile error during compilation with javac.

C:\workspace...\MyFileName.java:23

error: incompatible types: Object cannot be converted to String

I'm using version 131.

project configuration

Restarting the PC, does not make the error disappear.

0

There are 0 answers