There's nothing wrong with static methods in the right place. I use them regularly. What I would say, though, is that overuse of static methods is sometimes a sign that the programmer is really writing procedural code in Java, and isn't working in an object-oriented way.
I read this somewhere, too, and since then, I'm really paranoid about using static methods. I'm working on a fairly large (web-) project and noticed that many tasks can be done by static methods (such as file I/O, some simple mathematical functions, parsing strings, find and instantiating classes for me) - but others can not.
I'm using my best judgment and don't go out of my way to force methods that could be static not to be, but everytime I add a new static method to a class (there are classes in my project which have only static methods) I get a bad feeling.
Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
Niall Loughnane wrote:a fellow developer recently told me that static methods are bad,
what do you think?
He's wrong. Static methods are what they are: static. In the right situation, they are exactly what you need; and also probably slightly faster than non-static ones.
The question then is: when is the right time to use static methods? A couple I can think of:
Every single time someone makes an absolute statement like this, they are dead wrong.
Bu seriously...in programming, I don't believe there are absolutes. It may be correct that MOST of the time static methods are bad...but that is because most developers don't understand the right time, place, and way to use them, so they get abused.
You'll hear people say that the singleton is terrible, and should never be used...but again, in the right time and place, it is the perfect solution.
The trick is learning where and when that time is...
Never ascribe to malice that which can be adequately explained by stupidity.