Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!aioe.org!.POSTED!not-for-mail From: "javax.swing.JSnarker" Newsgroups: comp.lang.java.programmer Subject: Re: "Small" Program Challenge. Date: Mon, 18 Jun 2012 19:48:39 -0400 Organization: media lab? Lines: 118 Message-ID: References: <4fde76ce$0$287$14726298@news.sunsite.dk> <20ad5d23-f0a7-4926-9d99-b9dc0a7ea18e@googlegroups.com> NNTP-Posting-Host: 3urdS3lMyXHJXrtKy7vOkg.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:15398 On 18/06/2012 4:31 PM, Lew wrote: > On Monday, June 18, 2012 12:57:53 PM UTC-7, javax.swing.JSnarker wrote: >> On 18/06/2012 3:47 PM, Lew wrote: >>> Loading does not imply initialization, and in fact cannot. >> >> Wrong. Loading and initialization go hand-in-hand. >> >>> The JVM is forbidden to initialize a class except under specific >>> circumstances, a >> >> What? > > See JLS 12.4, which I cited upthread: Why did you write half a sentence and end it in mid-word, though? >> Wrong. Loading and initialization go hand-in-hand. > > Not according to the JLS. What authority are you using? The fact that initialization is required before use of a class (instantiation, invocation of a static method, whatever), and that loading is not required until the circumstances that permit and require initialization. Thus, loading will tend not to occur until right before use, and initialization will thus tend to occur right after loading. >> You haven't cited anything except my own post, and your quotation of >> *that* was a jumbled mess with some sections repeated for some reason. > > Again, I quoted the section I re-quoted in this post. I provided the link > *and* quoted the relevant content. How can you say I didn't? You didn't provide any link and you quoted some stuff from my post *twice*, for some reason. There seems to be a partial quote of it and a bit of inline commentary from you (criticisms, natch), followed by a second attribution line and then a quote of the entirety of my post, including the parts already quoted earlier. >> Wrong. Loading and initialization go hand-in-hand. > > Except according to the JLS. The fact that initialization is required before use of a class (instantiation, invocation of a static method, whatever), and that loading is not required until the circumstances that permit and require initialization. Thus, loading will tend not to occur until right before use, and initialization will thus tend to occur right after loading. >> Load the class. >> Initialize the class. > > Note - that is two steps, not one. However, there is little point in doing the first step until right before the second step, so in practice they should occur back-to-back. >> a call to A.foo() should return 100, not 0. If it can attempt to invoke >> foo before the static initializer has executed that would be violated. > > It can attempt to call 'foo()' before the initializer has executed. No, it generally can't. If the attempt succeeds and, as a consequence, foo() executes before the initializer has executed, then foo will incorrectly return 0. Therefore the attempt must not be made until the initializer has executed, except in the peculiar case that the attempt is known in advance to be guaranteed to fail. In which case there should have been a compile-time error earlier still. > This is exactly one of the circumstances that causes the initializers > to execute. You are confused. You seem to be thinking the order is Load class Attempt to call foo Initialize class But this can only be guaranteed not to violate the semantic requirements if the attempt is known to be sure to fail. If the attempt to call foo might succeed, then the order MUST be Load class Initialize class Attempt to call foo so that if the third step succeeds and foo begins executing, foo does not encounter things still in an uninitialized state that the spec guarantees must have been initialized before foo begins executing! > Read the JLS! I have referenced and quoted the relevant section twice now. And I've replied to it once, and it clearly states that initialization must occur *before* any invocation of a static method. Your suggestion that it can invoke it first and *then* initialize the class simply cannot fly. > I haven't seen any examples of reflection in this thread. How is the main method invoked? It obviously isn't a statically-compiled call from another class, and the only other invocation mechanism is reflection; therefore it is called reflectively, by something that behaves analogously to Class.forName(argv[1]).getMethod("main",ARRAY_OF_JUST_THE_STRING_ARRAY_CLASS).invoke(null,convertRestOfArgv);. >> initialized A yet, how can it be sure whether or not it has a method >> bar? On the other hand, if it's a non-reflective call the code calling >> bar won't even compile. > Why is the above quoted, but not responded to? -- 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.