强制使用Object迭代Collection <string>?

时间:2017-12-05 11:35:43

标签: java intellij-idea collections java-8 intellij-17

突然之间, 2017.1.5不允许我使用Collection<String>forach变量迭代String

简单的代码:

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

,其中

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

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

被标记为错误,并建议将变量methodPathString更改为Object

一开始,我认为IDE只是索引,一些后来编辑的代码的错误仍然出现,这不会让我感到烦恼,但实际上无法编译项目:

  

使用javac编译时编译错误。

     

C:\工作区... \ MyFileName.java:23

     

错误:不兼容的类型:对象无法转换为String

我正在使用版本131。

project configuration

重新启动电脑,不会使错误消失。

0 个答案:

没有答案