Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: trigger static init Date: Mon, 9 Apr 2012 10:31:11 -0700 (PDT) Organization: http://groups.google.com Lines: 32 Message-ID: <30681600.563.1333992671197.JavaMail.geo-discussion-forums@pbcuu8> References: <5605o7di8le7conanmf0g70p1ltipeqct4@4ax.com> NNTP-Posting-Host: 69.28.149.29 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1333992764 7547 127.0.0.1 (9 Apr 2012 17:32:44 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 9 Apr 2012 17:32:44 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Received-Bytes: 2094 Xref: csiph.com comp.lang.java.programmer:13460 glen herrmannsfeldt wrote: > Roedy Green wrote: > > What is the canonical way to explicitly trigger a static class to load > > and run thestatic init without actually invoking a real method? > > > you can't necessarily use newInstance since the class may not > > have constructors. > > As far as I know, a class automatically has a no argument constructor, > even if you don't write one. > > class myclass { > static int x; > } He meant no *accessible* constructors. If the constructor is not accessible, its existence is moot. And Java coding conventions call for type names to have an initial upper-case letter and be in camel case: 'MyClass'. > compiles just fine, as does creating an object from it. > > > Do you have to invent some dummy static method? > > Not that I know of. The rules for class initialization are quite explicitly listed in the JLS, which document is eminently useful no matter how much one may affect to loathe it. -- Lew