0

I have define a collection like List ids. I am wondering which is better

1) initialize in the declaration

2) initialize int he constructor.

user496949
  • 83,087
  • 147
  • 309
  • 426

2 Answers2

3

You should declarate it in the constructor, not only for readability but also for inheritance matters. You might want to inherit another class from that and maybe for that particular new class you would like to overwrite the constructor because it has different parameters.

mariana soffer
  • 1,853
  • 12
  • 17
0

Its same, but better readability would be within constructor.

Checkout my rules.

Also...

In terms of best practice the former is less error prone than the latter as someone could easily add another constructor and forget to chain it

Community
  • 1
  • 1
KMån
  • 9,896
  • 2
  • 31
  • 41