I recently started a new project, and I try to ensure that my instance variables are always initialized to some value, so none of them are equal to zero at any time. Below is a small example:
public class ItemManager {
ItemMaster itemMaster;
List<ItemComponentManager> components;
ItemManager() {
itemMaster = new ItemMaster();
components = new ArrayList<ItemComponentManager>();
}
...
}
The point is basically to avoid the tedious checking of zero before using an instance variable somewhere in the code. So far, it worked well, and you basically don't need a null value, since you can also check for an empty string or empty list, etc. I do not use this approach for variables with a limited range, since their scope is very limited, and therefore does not affect other parts of the code.
, , , - , . , ?