The interface in question is FileVisitor, which defines this method:

FileVisitResult preVisitDirectory(T dir, BasicFileAttributes attrs)
    throws IOException;

My really simple implementation is this:

public final class FailFastDeletionVisitor
    implements FileVisitor<Path>
{
    private final FileSystemProvider provider;

    public FailFastDeletionVisitor(final Path victim)
    {
        provider = Objects.requireNonNull(victim).getFileSystem().provider();
    }

    @Override
    public FileVisitResult preVisitDirectory(final Path dir,
        final BasicFileAttributes attrs)
        throws IOException // <-- HERE
    {
        return FileVisitResult.CONTINUE;
    }

    // etc etc    
}

At the point marked <-- HERE in this code extract, strangely enough, IDEA (since this is my IDE of choice) tells me that declaring that exception is unnecessary...

Since IDEA is not without bugs, I decided to try it out. I removed the exception and it compiled! So, IDEA is right.

And then I recalled that if you implemented Cloneable your were not required to throw CloneNotSupportedException, which is also a checked exception, for your code to compile (not that this is the canonical reommendation, of course). Even though Object's .clone() throws it.

And indeed, when you @Override clone() and do not declare it to throw CloneableNotSupportedException, it still compiles.

BUT.

Then I tried this:

final Callable<Void> callable = new Callable<Void>()
{
    @Override
    public Void call()
    {
        return null;
    }
}

Callable is supposed to throw Exception but so far it compiles; however, if I:

callable.call();

then this is a compilation error...

What is what?


EDIT OK, there is a MAJOR difference; Cloneable does not define clone(); Object does.

0

There are 0 best solutions below