Inspectopedia
 
2024.3

Design for extension

Warning
New
Last modified: 03 December 2024

Reports methods which are not static, private, final or abstract, and whose bodies are not empty.

Coding in a style that avoids such methods protects the contracts of classes from being broken by their subclasses. The benefit of this style is that subclasses cannot corrupt the state of the superclass by forgetting to call the super method. The cost is that subclasses are limited in their flexibility, in particular they cannot prevent execution of code in the superclass. Use the quick-fix to add the missing modifiers.

Example:

After the quick-fix is applied:

This inspection is intended for code that is going to be used in secure environments, and is probably not appropriate for less restrictive environments.