I recently wrote a class for an assignment in which I had to store names in an ArrayList (in java). I initialized the ArrayList as an instance variable private ArrayList<String> names
. Later when I checked my work against the solution, I noticed that they had initialized their ArrayList in the run()
method instead.
I thought about this for a bit and I kind of feel it might be a matter of taste, but in general how does one choose in situations like this? Does one take up less memory or something?
PS I like the instance variables in Ruby that start with an @ symbol: they are lovelier.
(meta-question: What would be a better title for this question?)