Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "javax.swing.JSnarker" Newsgroups: comp.lang.java.programmer Subject: Re: "Small" Program Challenge. Date: Fri, 22 Jun 2012 18:30:19 -0400 Organization: media lab? Lines: 27 Message-ID: References: <4fde76ce$0$287$14726298@news.sunsite.dk> <7kIDr.12088$Bp1.3039@newsfe10.iad> NNTP-Posting-Host: QMvkqwgQTSa35o56g4Mhjg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: NewsTap/3.5.5 (iPhone/iPod Touch) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:15534 On 22/06/2012 3:54 PM, Daniel Pitts wrote: > How I would expect this to work in reality. > > 1. Load class > 2. get a reference to the static method "void main(String[])" > 3. Attempt to execute that reference > 3.1 Causes class initialization before execution. > 3.2 actual execution occurs. That has a problem, though, in that class initialization will happen on every method call, resulting in multiple initializations, if it's part of "attempt to execute the reference" rather than (as the spec says) something the JVM does immediately *before* the first such attempt (or other action that requires an initialized class for the action to begin). I suppose you could change 3.1 to "see if the class is initialized, and if not, initialize it", but even that would add to *every method call* the overhead of a test-and-branch, and would still be dodgy at best on spec-adherence grounds. -- public final class JSnarker extends JComponent A JSnarker is an NNTP-aware component that asynchronously provides snarky output when the Ego.needsPuncturing() event is fired in cljp.