Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (10.2k points)

Let's say I have a class designed to be instantiated. I have several private "helper" methods inside the class that do not require access to any of the class members, and operate solely on their arguments, returning a result.

public class Example {

   private Something member;

   public double compute() {

       double total = 0;

       total += computeOne(member);

       total += computeMore(member);

       return total;         


   private double computeOne(Something arg) { ... }

   private double computeMore(Something arg) {... } 

Is there any particular reason to specify computeOne and computeMore as static methods - or any particular reason not to?

It is certainly easiest to leave them as non-static, even though they could certainly be static without causing any problems.

1 Answer

0 votes
by (46k points)
I prefer such helper methods to be private static; which will make it clear to the reader that they will not modify the state of the object. My IDE will also show calls to static methods in italics, so I will know the method is static without looking the signature.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories