为什么在这个foreach循环中,elem不被识别为一条路径,而我只能在它上调用对象方法?
public class TypeOption<Path> implements Option<Path> {
@Override
public void apply(String arg, Collection<Path> c) {
for (Path elem : c) {
if (Files.isExecutable(elem)) c.remove(elem);
}
}
}这条线
if (Files.isExecutable(elem)) c.remove(elem);正在制造麻烦,上面说
The method isExecutable(java.nio.file.Path) in the type Files is not applicable for the arguments (Path)发布于 2014-12-25 12:41:29
这是因为Path在这里是一个类型参数--您已经声明了一个泛型类型,Path是类型参数。我怀疑你*通缉:
public class TypeOption implements Option<Path> {此时,Path引用名为Path的现有类型,并用于Option<T>的类型参数(或Option的类型参数)。
https://stackoverflow.com/questions/27647271
复制相似问题