L
Lew
Patricia said:Eric Sosman wrote:
...
The criterion could be described better. Maybe it should be something
like "needs very careful design and documentation to achieve correct
extension". A big chunk of the Object API documentation, for example,
discusses the rules for equals, hashCode, and the relationship between
them in classes that override them.
It seems to me that the best use of this type of tool for that sort of
check is to prevent such things being done casually. The extra
hoop-jumping for turning off the check in a class is not that big
compared to the work that needs to be done to ensure correct extension.
Of course, if the powers-that-be forbid turning off the check, there is
a much bigger problem.
What we're overlooking here is that 'Object' actually does violate the rule, and that it's not actually a bad rule.
The exception probes the rule - what we need to understand is _why_ 'Object' breaks the rule, and the dangerous behaviors it permits thereby.
As Patricia aptly points out, it takes a mountain of documentation, comprising not only the voluminous Javadocs but volumes of articles, chapters in _Effective Java_, and innumerable blog posts to prevent errors involving mismatches between 'equals()', 'hashCode()', 'toString()', and where applicable, 'compareTo()', because 'Object' is most definitively not "designed for extension" in the sense intended by the principle.
A class designed for extension in this context means designed *for the compiler to enforce extensibility*. The downside to the rule-breaking (intentional though it be) in 'Object' is that it allows, nay encourages error. The exact sort of error that Checkstyle is trying to prevent you from committing.
So shut the front up, get over yourself, and understand the reasons for therule. Yes, it can and even should be violated under certain circumstances.. But don't present 'Object' as a counterexample when in fact it is the poster child for why the rule is valid.