Hi I have a philosophical/design question about constructor in
java vs initialization of member variable... This is a basic question but I need to know the rational behind this for my personal culture!
Let's begin with a little bit of code.
Given this class hierarchy:
And then this initialization:
Here the sequence of call:
With this code, Java will call the ArtistInABand() contructor before initializing the Guitarist.effectMap. When the Guitarist.setupYourInstrument() is called , the effectMap will be null...
Here comes the question: Why does java don't initialize member variables before calling the parent constructor?
NOTE: One advised developer will tell me: Don't call abstract method from the constructor... This is a workaround that prevents this kind of problem... This answer leave my question unresolved...
Thanks!