Add an @override keyword on methods to help detect errors

Number:rdar://7215146 Date Originated:10-Sep-2009 11:34 PM
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification:Enhancement Reproducible:N/A
Overriding a superclass' method or implementing a protocol with optional methods can result in subtle bugs, including:

* Accidentally overriding a superclass' method.
* Misspelling a superclass' method, thus not actually overriding it.
* Misspelling an optional protocol method, thus not actually implementing it.

Java provides an '@override' annotation to handle these cases:


And C# provides an 'override' keyword:


A similar keyword in Objective-C, like @override, could work the same way:


If you mark a method with @override, it *must* be declared in either the superclass or an optional protocol method.  If not, you get a compiler error (or maybe just a warning).

Perhaps an @implement keyword could be used for protocols since you aren't strictly overriding anything:

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView

This may be polluting keywords too much, and @override could be used for both cases, even if it's not strictly correct for protocols.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!