InspectionGadgets: erroneous error reported for inherited final toString() method

IG displays an erroneous error message suggesting that a class should probably implement toString(), even if the class in question already inherits a final implementation of that method. If the class inherits a toString() method, in some cases that might be sufficient (user checkbox option: ignore inherited Object.toString() overrides?); if it's a final implementation no error should be reported.

3 comments


Okay, I guess, although I have to wonder what if there is any plausible engineering reason to have a final "toString()" method, without the entire class being final.

0

I don't want to create new thread for this, sorry :)
I suppose this bug comes from InspectionGadgets:

http://www.intellij.net/tracker/idea/viewSCR?publicId=29130

0

Quite possibly in many cases there may not be a 'sound engineering reason' for having a final toString() method in a non-final class, but that wasn't my point. The point is that it is an error for IG to suggest that the subclass should provide a toString() method, because to do so would result in a compilation error.

In any case, it's not beyond the bounds of possibility that a particular (say, abstract) class could mandate a design pattern that would permit it to construct a valid string representation for any possible subclass. In such cases it would be perfectly reasonable for the abstract class to provide a final toString() implementation. The Java typesafe enum pattern as described by Joshua Bloch is one such example (he suggests that toString() could be overridden by subclasses, but there are applications where this would not be appropriate or desirable).

0

Please sign in to leave a comment.