Vote up, vote down. It doesn't matter which - just vote! Login and vote now.
By sharrissf
via dsoguy.blogspot.com
Published: Jan 25 2008 / 17:34
I was chatting with some fellow geeks earlier this evening and it occurred to me that I've said to people that they should almost ALWAYS use static and also told people they should almost NEVER use static.
Comments
colmsmyth replied ago:
Simplistic assessment of static. Now all we need is for someone to write a similar post on why they don't like final or synchronized.
puredanger replied ago:
I don't like final or synchronized. And man, void just sucks.
dzonelurker replied ago:
null sucks even more.
sharrissf replied ago:
Fair enough, what parts of the post are unclear? Do you disagree with the assertion? Is there some aspect of static that I should have mentioned to make the point better? Are you saying that it is so obvious not to use non-static inner classes as to be silly?
ChiralSoftware replied ago:
I had to give a negative vote on this. Using static vs not has nothing to do with whether you "love or hate" static. It has to do with what is needed. In general, static members are contrary to object-oriented design, but sometimes that is needed. For example, no Java program could even begin execution without a static main method!
As for inner classes... if it's static, ask yourself why you're making it an inner class? Again, static inner classes have their place; the key is to know what that place is.
sharrissf replied ago:
Ok, but one minor point, you say static inner classes have their place and I agree. I was mostly saying that non-static inner classes are over used not static ones.
matt_yucha@yahoo.com replied ago:
Voted up - for some odd reason I really enjoy discussions about statics in Java. Two places I use statics are:
1) Static factory methods.
2) Static init blocks - especially for compiling regexp patterns that never change.
ikarzali replied ago:
voted up because I got bit by misuse of static this weel. A certain web framework which shall remain nameless locked up the entire app server when a couple of threads dead-locked, the framework couldn't run for ANY requests anymore. I think this sort of problem is the point of the original post...
willcode4beer replied ago:
ahhh, static variables, the path to memory leaks and multi-threaded pain
Voters For This Link (19)
Voters Against This Link (7)