-2

One advantage which I could think of was to prevent accidental update to a class variable in future enhancements. I would like to know if there are any other advantages.

This answer for C# mentions that there would be a minor performance improvement while using static method. Does Java compiler have a similar processing as well?

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Gautham M
  • 4,816
  • 3
  • 15
  • 37

1 Answers1

2

In my opinion, the primary use cases for private static methods are reuse and readability of public static methods.

Readability Suppose you have a large public static method with many branches, then it might be beneficial to readability to have each branch handled by a private static method. This is the approach advocated by books such as Clean Code.

Reuse Suppose you have a number of public static methods with duplicated code, then it is usually a good idea to place the duplicated code in a private static method (unless of course the duplicated code is useful as a utility method in its own right).

Jeroen Steenbeeke
  • 3,884
  • 5
  • 17
  • 26