突然之间,intellij-idea 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();
}
被标记为错误,并建议将变量methodPath
从String
更改为Object
。
一开始,我认为IDE只是索引,一些后来编辑的代码的错误仍然出现,这不会让我感到烦恼,但实际上无法编译项目:
使用javac编译时编译错误。
C:\工作区... \ MyFileName.java:23
错误:不兼容的类型:对象无法转换为String
我正在使用java-8版本131。
重新启动电脑,不会使错误消失。