3 ms·
Java's @Override is not only optional, but fails to address an important use case: when you don't want to override anything with your method, and then the base
by ninkendo 12y ago
Java's @Override is not only optional, but fails to address an important use case: when you don't want to override anything with your method, and then the base class has a method added to it with the same name as yours. (Or if you simply didn't know that the base class had that method.) Swift will make sure you don't inadvertently override base class functionality by requiring you to use it.
- cromwellian 12y agoIn Java, you'd just add a 'final' keyword to the base method and you'd get a compile time error if someone accidentally tried to override it. If you want the equivalent of !@Override, a) you can do it with Java8 annotation types and a checker or b) you can just declare the method private. I'm sure Swift's version also fails to address all of the edge cases people might want to catch. No type system can be complete and catch every use case.
- mercurial 12y agoYou can't always do b) since your object has to, well, do something. Personally, I'd like to make inheritance strictly opt-in (as in, classes marked final per default), if anything this may be enough to make some people think twice about the let's-use-inheritance-to-share-code antipattern.