Issue in Java "Utility class without private constructor" inspection gadget
This useful inspection creates a compilation error when applying fix while the utility class has a utility subclass (the subclass does not compile any more).
In this case, a protected constructor should be generated instead of a private constructor, and the existence of a protected constructor should not raise an error.
Do you agree?
Please sign in to leave a comment.
Hello Olivier,
OD> This useful inspection creates a compilation error when applying fix
OD> while the utility class has a utility subclass (the subclass does
OD> not compile any more).
OD>
OD> In this case, a protected constructor should be generated instead of
OD> a private constructor, and the existence of a protected constructor
OD> should not raise an error.
OD>
OD> Do you agree?
Which version of IntelliJ IDEA are you using? As far as I remember, this
is fixed in 6.0 beta.
--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"
Out of curiousity, of what possible use is subclassing a utility class? The whole point of utility classes is to cover those cases where you have to break out of OO and punt to a procedural approach. That makes subclassing a utility class a very odd thing to do, I think.
If I had every considered that anyone would subclass a utility class, I would probably have written an inspection to prevent it.
--Dave Griffith
Hey Dave,
Dave Griffith wrote:
Don't worry, I have. You can find the "Class extends utility class" inspection in the inheritance issues category since build #5557. Great minds think alike;-)
Bas