«« Next » « Previous
«« Next » « Previous

Link Details

Vote up, vote down. It doesn't matter which - just vote! Login and vote now.
Link 63346 thumbnail

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.
  • 19
  • 7
  • 1386
  • 582

Comments

Add your comment
User 229644 avatar

colmsmyth replied ago:

1 votes Vote down Vote up Reply

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.

User 214988 avatar

puredanger replied ago:

0 votes Vote down Vote up Reply

I don't like final or synchronized. And man, void just sucks.

User 236137 avatar

dzonelurker replied ago:

0 votes Vote down Vote up Reply

null sucks even more.

User 207083 avatar

sharrissf replied ago:

0 votes Vote down Vote up Reply

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?

User 259836 avatar

ChiralSoftware replied ago:

2 votes Vote down Vote up Reply

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.

User 207083 avatar

sharrissf replied ago:

0 votes Vote down Vote up Reply

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.

User 250139 avatar

matt_yucha@yahoo.com replied ago:

0 votes Vote down Vote up Reply

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.

User 199742 avatar

ikarzali replied ago:

1 votes Vote down Vote up Reply

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...

User 209464 avatar

willcode4beer replied ago:

0 votes Vote down Vote up Reply

ahhh, static variables, the path to memory leaks and multi-threaded pain

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.