javaeclipsestaticcoding-style

Java make methods static when possible, good practise?


I set my compiler to warn me about methods that could be made static.

These methods are mostly some helpers to do calculations, set attributes on passed objects and so on.

Should I make them static, or is this a sign that my coding style is city (CN)?


Solution

  • Be wary of using static methods for things that you would like to abstract later. Static methods do not support swapping implementations because have a hard link between the consuming class and the implementation class.

    That being said, I think there are still places where static methods are appropriate (Utility classes).