If a class has no state, should all the methods be static?

java, oop, static

Solution

If your class provides only utility methods (like yours), I believe it's better to:

- make the class `final` (there's no point to extend it)

- define а `private` constructor to avoid any attempt to create an instance of the class

- make all the methods `static`.

Problem

Lets say I have a Helper class like with a few methods ``` public class SomeClassesHelperClass(){ public List removeDuplicatesFromTheGivenList(List someList){ // code here } public int returnNumberOfObjectsThatHaveSomeSpecialState(List someList){ // code here } } ``` What are the advantages / disadvantages of making the methods in this class static? Which is the better practice?

Original source