Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: praise Date: Tue, 25 Feb 2014 16:46:32 -0800 Organization: A noiseless patient Spider Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 26 Feb 2014 00:46:38 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="cf1bf8d9b7c3a87486f91ce5582b1426"; logging-data="9925"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IOWTtQs4FnLSkj8ag/nA0RV6oA3LQ+k8=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: Cancel-Lock: sha1:aa4UhDPUGoOm27hyun0FSjTrQYw= Xref: csiph.com comp.lang.java.programmer:27592 On 2/25/2014 3:01 PM, Lew wrote: > Stefan Ram wrote: >> One can even learn from it notions such as »package-tree >> semantics« versus »traditional package semantics« or facts >> such as »a class's constructors and methods can run prior to >> its initialization« (»its« = »the class'«). > > Strange. The JLS says: > http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.4 > "A class or interface type T will be initialized immediately before the first occurrence of any one of the following: > [the class is used] > So that contradicts. > The paragraph Stefan is referring to, I think, is: " There is, however, one corner case that demands special treatment. It is possible, though generally not desirable, to execute methods or constructors prior to initialization. This can happen when a class hierarchy contains a circularity in its static initialization." So it looks to me like the JLS is implying a "best effort" to initialize a class before it is used, but can't absolutely guarantee it in all cases. It would be an interesting experiment to try to write some code to reproduce the case where a ctor is called before its initialization.