New inspections proposal: overly strong declaration

In the same spirit as "overly strong typecast", IDEA could check for variables declared with a type stronger than needed. The quickfix would find out which superclass contains only the necessary

Of course, this should only be triggered for local variables that are never leaked. As an alternative, there could be no inspection at all, but only an intention that can be triggered at the same conditions.

1 comment

I actually coded this one up a while back. The results were very odd. If you blindly assign all local variables to the strongest possible superclass, you end up learning far more about the inheritance heirarchy of the core Java classes than you ever needed to know. Swing code in particular ends up weird, with a bunch of things declared as "Component" or worse, something like "AbstractButton". Overall, the most evocative description I can give of the results is that you get code that looks 'melted'. It's the only inspection that I coded and then did not ship.

A better possibility, which I haven't tried, is to weaken overly strong declarations, if you can weaken it to a interface, rather than any old superclass. That would be worth trying, but I'm only 50-50 on whether the results would be worth using.

--Dave Griffith

0

Please sign in to leave a comment.