Java beginner: initializing class variables

I just read the SUN java code conventions ; a very good document by the way. And I read it

6.3 Initialization: Try to initialize local variables where they are declared. The only reason not to initialize the variable where it is declared, if the initial value depends on some calculations that occur in the first place.

And I was wondering if they have Class variablesthe same sentence or not, for example, I have:

public class NNmatrix {

    protected ArrayList<ArrayList<Double>> matrix;     // line 1
    public NNmatrix() {
        matrix = new ArrayList<ArrayList<Double>>();     // line 2
    }
    /**
     * 
     * @param otherMtrx
     */
    public NNmatrix(final ArrayList<ArrayList<Double>> otherMtrx) {
        final int rows = otherMtrx.size();
        matrix = new ArrayList<ArrayList<Double>>(rows);  // line3
        for (int i = 0; i < rows; i++) {
            this.matrix.add(new ArrayList<Double>(otherMtrx.get(i)));
        }
    }
}

# variable, ( ), " 2" " 3", # () , .

:

  • , ..?
  • , , , # @line 3 @ 1?
+5
4

, . , ( nitpick).

, , , .

jvm , , , .

+4

, , . Java , , .

- , . , , , , , . , .

case, , .

, .

+1

, , .

, , , - . , (, , ). , - , .

+1

, , , . , - , .

  • , , , . , .

  • , , vs . , , System.out, .

0

All Articles