Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 11 Apr 2012 09:04:54 -0500 Date: Wed, 11 Apr 2012 07:04:54 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: trigger static init References: <5605o7di8le7conanmf0g70p1ltipeqct4@4ax.com> <17423607.56.1333992983521.JavaMail.geo-discussion-forums@pbkr6> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 30 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.201.141 X-Trace: sv3-zOGMFeTk4530VthgRe3f8l0Lw6ui/j5UpCr36JVf9wjauof2p2PKG7PVWaAtWN7CDvBi73wry1O44XU!itW3pjgYuJhWbX+WCP9jvvpuoXkb2llawlwlPcU71oQCFfRJD1NmC7D6Nhy9DpZHKePltU2akFVP!YSDZUOc9m8xqCQaOMXo/g6b+3lovbAa7Dc/m4CeLIA9uQTU= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2646 Xref: csiph.com comp.lang.java.programmer:13475 On 4/11/2012 5:52 AM, Andreas Leitgeb wrote: > Lew wrote: >> Referencing the 'class' literal does not incur class initialization. > > from JLS 12.4.1: > A class [...] T is initialized immediately before first [...] > T is a class and an instance of T is created. > T is a class and a static method declared by T is invoked. > A static field declared by T is assigned. > A static field declared by T is used [ ... and not constant ... ] > T is a top-level class, and an assert statement (ยง14.10) lexically > nested within T is executed. > > Does using a class-literal in "synchronized(T.class) {...}" count > in for implicitly using the monitor-field of the Class-instance, or is > it strictly undefined (or defined somewhere else)? > > Btw., I don't understand the point about assert. If the assert is > lexically nested in T and gets executed, then I'd have naively thought, > that one of the first two points would necessarily have happened, > anyway, before the assert could be reached. What am I missing here? > Suppose S is a static class defined in T. I interpreted that as meaning that executing an assert in S would trigger initialization of T. Or suppose S is non-static, but the assert is in its static code. Patricia