variable scope inside of parametrized method java generics

why is it that inside this foreach loop, elem is not recognized as a Path, which it is, and I can only call Object methods on it?

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);
        }
    }
}

this line

if (Files.isExecutable(elem)) c.remove(elem);

is causing the trouble, it says

The method isExecutable(java.nio.file.Path) in the type Files is not applicable for the arguments (Path)
Jon Skeet
people
quotationmark

It's because Path is a type parameter here - you've declared a generic type, with Path as the type parameter. I suspect you *wanted:

public class TypeOption implements Option<Path> {

At that point, Path refers to the existing type called Path, and is used for the type argument to Option<T> (or whatever the type parameter is for Option).

people

See more on this question at Stackoverflow