Article View: borland.public.jbuilder.java.language
Article #14980Re: Illogical constructor behaviour?
From: Tor Iver Wilhelmsen
Date: Thu, 22 Jul 1999 00:00
Date: Thu, 22 Jul 1999 00:00
32 lines
2247 bytes
2247 bytes
Tom.Eugelink@OVSoftware.com writes:
> Right, and that is exactly where IMHO the problem is. It should be
> done at the moment the variable are allocated, because there is no
> reason to do it later. (And doing it later causes problems.)
The object is allocated and zeroed by the "new" VM instruction - then
the constructor is called to initialize. Your solution would mean
either:
1) Class files would have a data segment of "defaults" in addition to
the already present String heap. Here you would only be able to
initialize with primitive type constants - very limiting.
or
2) Calling the super constructor would be postponed until directly
declared fields had been initialized. This has two major drawbacks:
* The initialization code cannot invoke - directly or indirectly -
non-static methods or fields in the superclass, since those
aspects of the object aren't in a "proper" state.
* If you allow initialization to happen both before and after
invocation of the superclass' constructor, you start to
differentiate between initializations that occur outside from
those declared inside the constructor method.
I vastly prefer the current situation, where the behaviour of
constructors are well-defined and known to the programmers. That the
programmer should avoid invoking non-final/private methods in a
contructor can be thought of as a programming caveat.
Technical Details
Message-ID:
<uogh59kck.fsf@sds.no>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3789a7ea.1163072@forums.inprise.com> <uzp1241hv.fsf@sds.no> <378adee2.3105084@forums.inprise.com> <uhfn8aph8.fsf@sds.no> <378c7224.5379925@forums.inprise.com> <MPG.11f734ffaf88e14d989683@forums.inprise.com> <3792d12a.4122557@forums.inprise.com> <upv1osstw.fsf@sds.no> <379424a2.91026959@forums.inprise.com> <u1ze3g3bj.fsf@sds.no> <3796c981.4100195@forums.inprise.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,c150801d0979e255 X-Google-Attributes: gidf74b3,public From: Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no> Subject: Re: Illogical constructor behaviour? Date: 1999/07/22 Message-ID: <uogh59kck.fsf@sds.no> X-Deja-AN: 503927572 Sender: towi@SDSA1761 References: <3789a7ea.1163072@forums.inprise.com> <uzp1241hv.fsf@sds.no> <378adee2.3105084@forums.inprise.com> <uhfn8aph8.fsf@sds.no> <378c7224.5379925@forums.inprise.com> <MPG.11f734ffaf88e14d989683@forums.inprise.com> <3792d12a.4122557@forums.inprise.com> <upv1osstw.fsf@sds.no> <379424a2.91026959@forums.inprise.com> <u1ze3g3bj.fsf@sds.no> <3796c981.4100195@forums.inprise.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language