It would be nice to have tool to statically describe overwrite policy


#1

When you inherit class you are forced to call its constructor, but when you overwrite its method you can do what ever you want: the only thing class author may use is informal documentation.
I believe that in most cases class may have one of the following policies:

  • Always call super method first (like in constructor)
  • Always call super method as last line (and return its result)
  • Never call super method.

It would be nice to have some annotation like OverwritePolicy(FIRST), OverwritePolicy(LAST) etc.
Compiler may force class inheritor to obey it (refuse to compile if super is not called for example), and for Java we may use inspections.

I belive that by expressing such semantic in formal manner and making compiler/IDE check it statically we may improve code quality