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:36:23 -0700 (PDT) Organization: http://groups.google.com Lines: 17 Message-ID: <17423607.56.1333992983521.JavaMail.geo-discussion-forums@pbkr6> 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 1333993374 13715 127.0.0.1 (9 Apr 2012 17:42:54 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 9 Apr 2012 17:42:54 +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: 1720 Xref: csiph.com comp.lang.java.programmer:13462 Jukka Lahtinen wrote: > Roedy Green writes: >> What is the canonical way to explicitly trigger a static class to load >> and run thestatic init without actually invoking a real method? > > I suggest Class.forName(String classname), if you just want to avoid > invoking a method of the class to be loaded and don't mind invoking > one of the Class class. > > If you insist on not invoking any method of *any* class and thus don't > want to use Class.forName, you can refer to some public static attribute > of the class. Bear in mind that the 'class' literal does not apply here. Referencing the 'class' literal does not incur class initialization. -- Lew