>> If you need to use this trick, make sure that the "helper"
>> method cannot be overridden in a sub-subclass! It will run
[quoted text clipped - 3 lines]
>> the incompletely initialized object. Making it private and/or
>> static, as above, is a good defense against that error.
Making it static is the only choice for a "trick", hence it can not be
overridden. Instance of the class being initialized is not yet
available, so worry about its initialization is not needed here.
> Joshua Bloch goes into this point in /Effective Java/.
>
> Never call overridable methods from a constructor.
That's impossible in Eric's "trick".
SubClass() { // constructor
SuperClass( /* 'this' is not available here! */ );
// that's what J. Bloch is dissuading from doing
overridableMethod();
...
> Generally, don't do very much work in the constructor. Never do work in
> the constructor not related to construction of the object.
Agreed.
piotr
Piotr Kobzda - 06 Apr 2007 12:55 GMT
>> Joshua Bloch goes into this point in /Effective Java/.
>>
>> Never call overridable methods from a constructor.
>
> That's impossible in Eric's "trick".
Or, that's the only possibility for a "trick". The answer depends what
sense of the statement it refers to.[1] :)
> SubClass() { // constructor
> SuperClass( /* 'this' is not available here! */ );
Of course, correct syntax is:
super( /* 'this' is not available here! */ );
> // that's what J. Bloch is dissuading from doing
> overridableMethod();
> ...
piotr
[1] -- I don't know, if for all English speakers the main sense
distinction is obvious here -- for me, it isn't. English is not my
native language, hence it sometimes appears difficult to me to get a
right sense of the sentence, especially in context of discussion in mind.
BTW, it sometimes happens also that my English sentences are not correct
(even though I'm hardly trying to avoid it), and they are possibly not
even understandable for others. My apologies to all for that.
Gordon Beaton - 06 Apr 2007 13:51 GMT
> BTW, it sometimes happens also that my English sentences are not
> correct (even though I'm hardly trying to avoid it), and they are
> possibly not even understandable for others.
I don't normally comment on language style, but just couldn't resist
here, given the context: "hardly trying" means the opposite of "trying
hard", which is what I think you meant to say.
/gordon
--
Piotr Kobzda - 06 Apr 2007 14:40 GMT
> I don't normally comment on language style, but just couldn't resist
> here, given the context: "hardly trying" means the opposite of "trying
> hard", which is what I think you meant to say.
Yes, that's what I meant. :) Thanks!
piotr