When filling in the values for a class-wide (static) data structure/collection (in this case a 2D array), is it generally better to save the values directly into the static one, or should a temporary variable be created in the method?
To make it more clear:
public class MyClass{
private static int[][] table;
public void setTable(int row, int col){
table = new char[row][col];
// fill table (eg. table[i][j] = 5;)
}
//// OR THIS//////
public void setTable(int row, int col){
int[][] tempTable = new tempTable[row][col];
// fill tempTable
table = tempTable;
}
}
Creating a temporary variable feels redundant and useless here. But are there cases where this would be advised? Possibility of program crashing halfway through execution of method and corrupting data? Multi-threaded applications?
I hope the question isn't subjective, just want to know if there is inherently something wrong with just filling it in directly.
static final int[][] table = setTable(int, int), and use the second approach.