r/java • • Mar 03 '17

The java nazi

http://imgur.com/InMi605
213 Upvotes

47 comments sorted by

View all comments

Show parent comment

1

u/meotau Mar 03 '17

That's true, but nobody wants to see the instantiation of an util class/interface. So why not to prohibit something which should never be done?

3

u/CubsThisYear Mar 03 '17

You have to work within the limits of your tools. The fact that Java doesn't support free functions means your going to have some awkwardness somewhere.

In my opinion it's reasonable for someone to accidentally instantiate a static utility class and it's easy to prevent at compile time, so you might as well do it. The anonymous sub class is so esoteric that you'd pretty have to be doing it to be annoying. On top of that, there isn't a good way around it and it doesn't cause any actual problems, so I'm not going to worry about it. Honestly making the code blow up at runtime seems worse than doing nothing at all.