From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: Quick question regarding limited type return syntax Date: Mon, 04 Aug 2014 12:42:42 +0200 Organization: A noiseless patient Spider Message-ID: References: <166aaec5-5e9c-40e0-9b07-9b9c7d5f7f33@googlegroups.com> <16a6846f-2964-438a-ab9b-2029075f7924@googlegroups.com> <20m59uxjlygw$.2mpabkt469vp.dlg@40tude.net> Reply-To: nonlegitur@futureapps.de Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 4 Aug 2014 10:42:42 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="b96887e80893c84a90c3007226ca0d1c"; logging-data="9589"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sVdwXVjxtur9pPQm2wUjkFDusCUw3XHo=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Cancel-Lock: sha1:yF7daIWYgu8JjbPlWq9ZCCneicY= Xref: news.eternal-september.org comp.lang.ada:21434 Date: 2014-08-04T12:42:42+02:00 List-Id: On 04.08.14 11:24, Niklas Holsti wrote: > As I understand it, even in the languages which do > have specific constructor/destructor facilities, there is no requirement > or check that a constructor must initialize all the components of the > object (but I'm not sure how Java works in this case). Java lets you write Ada: class T { public T() { this.foo(); } protected void foo() {} } class S extends T { public Integer I; public S() { // calls super // I not initialized (and not allocated) this.I = 1; } @Override protected void foo() { this.I += 1; } } class Dispatching { public static void main(String[] args) { S Y = new S(); } } This program will stop after throwing a NullPointerException. If S.I is made an int, the default value is 0, and the above program is considered bad style(*). C++, I think, lets "this" stand for the type at the current "level" during construction, so there is no dispatching to lower levels IIUC; however, Stroustrup mentions some pointer tricks that let the programmer circumvent the restriction. (*) http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html