2 prettied up footnote.
source | link

A fairly common reason (in Java) would be for initializing immutable field variables in a constructor by using a simple private static method to reduce constructor clutter.

  • It is private: external classes should not see it.
  • It is static: it can perform some operation, independent(*)1 of the state of the host class.

A somewhat contrived example follows...

eg:

public class MyClass{
    private final String concatenated;

    public MyClass(String a, String b){
        concatenated = concat(a,b);
    }

    public String getConcatenated(){
       return concatenated;
    }

    /**
    *  Concatenates two Strings as `s1---s2`
    **/
    private static final String concat(String s1, String s2){
        return String.format("%s---%s", s1, s2);
    }
}

(*) Assuming it has no interaction with other1 static variables.Assuming it has no interaction with other static variables.

A fairly common reason (in Java) would be for initializing immutable field variables in a constructor by using a simple private static method to reduce constructor clutter.

  • It is private: external classes should not see it.
  • It is static: it can perform some operation, independent(*) of the state of the host class.

A somewhat contrived example follows...

eg:

public class MyClass{
    private final String concatenated;

    public MyClass(String a, String b){
        concatenated = concat(a,b);
    }

    public String getConcatenated(){
       return concatenated;
    }

    /**
    *  Concatenates two Strings as `s1---s2`
    **/
    private static final String concat(String s1, String s2){
        return String.format("%s---%s", s1, s2);
    }
}

(*) Assuming it has no interaction with other static variables.

A fairly common reason (in Java) would be for initializing immutable field variables in a constructor by using a simple private static method to reduce constructor clutter.

  • It is private: external classes should not see it.
  • It is static: it can perform some operation, independent1 of the state of the host class.

A somewhat contrived example follows...

eg:

public class MyClass{
    private final String concatenated;

    public MyClass(String a, String b){
        concatenated = concat(a,b);
    }

    public String getConcatenated(){
       return concatenated;
    }

    /**
    *  Concatenates two Strings as `s1---s2`
    **/
    private static final String concat(String s1, String s2){
        return String.format("%s---%s", s1, s2);
    }
}

1 Assuming it has no interaction with other static variables.

1
source | link

A fairly common reason (in Java) would be for initializing immutable field variables in a constructor by using a simple private static method to reduce constructor clutter.

  • It is private: external classes should not see it.
  • It is static: it can perform some operation, independent(*) of the state of the host class.

A somewhat contrived example follows...

eg:

public class MyClass{
    private final String concatenated;

    public MyClass(String a, String b){
        concatenated = concat(a,b);
    }

    public String getConcatenated(){
       return concatenated;
    }

    /**
    *  Concatenates two Strings as `s1---s2`
    **/
    private static final String concat(String s1, String s2){
        return String.format("%s---%s", s1, s2);
    }
}

(*) Assuming it has no interaction with other static variables.