Why does it compile when casting to an unrelated interface? [duplicate]

The compiler does not know that this won’t work: You could have a subclass of BlackInk that implements Printable. Then the cast would be fine.

In situations where the compiler knows it won’t work, you will get an error.

For example, if you make BlackInk final (so that there can be no subclasses) you get an error.

Leave a Comment