Re: calling own methods from constructor
Andreas Leitgeb wrote:
Actually, I tried to explain, why I was rambling about static methods
in response to your example.
No, you tried to be sarcastic and to make my answer seem wrong even
though it was precisely what you asked for.
Now, that you've made your point clearer, namely that getClass()
behaves like a virtual method overridden for *every* class, I even
understand it.
And it even exactly fits the parameters of your original question.
I'm just not yet convinced that this particular pattern, which is already
handled by JVM-magic (rather than by the compiler synthesizing those
virtual methods), would say "it's good to be able to call overridable
non-static methods from a constructor" sufficiently loudly. ;-)
I didn't ever say that it was good in such a general sense, thank you
very much for shifting the context yet again.
You asked if there were specific cases where it was good to use an
overridable (you never said 'final' until you started pulling your "no
true Scotsman" routine) method. I pointed out such.
"Loudness" was not part of your request.
It's just that there are occasionally (!) times when an overridable
method (though not necessarily a 'final' one, since even 'final'
methods can call overridable methods in turn) can be usefully called
inside a constructor (or initializer, equivalently). That was the
parameter of the original question, and that has been demonstrated.
Twice over, now.
--
Lew