Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!feeder.erje.net!newsfeed.utanet.at!newsfeed01.chello.at!newscore.univie.ac.at!aconews-feed.univie.ac.at!aconews.univie.ac.at!not-for-mail Newsgroups: comp.lang.java.programmer From: Andreas Leitgeb Subject: Re: calling own methods from constructor References: <41ac2ca5-83e8-4b80-92af-9704b373ec37@q36g2000yqn.googlegroups.com> <304a8aef-3852-4817-b5a7-5468fcdf11a1@x18g2000yqe.googlegroups.com> Reply-To: avl@logic.at User-Agent: slrn/pre0.9.9-111 (Linux) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: Date: 07 Apr 2011 20:31:26 GMT Lines: 24 NNTP-Posting-Host: gamma.logic.tuwien.ac.at X-Trace: 1302208286 tunews.univie.ac.at 60386 128.130.175.3 X-Complaints-To: abuse@tuwien.ac.at Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2943 Lew wrote: >> >> > Andreas Leitgeb wrote: >> >> >>> Is there any *good* use of having the constructor call a method that >> >> >>> actually *can* be overridden in a subclass? ... >> >> > Foo() { [...] = [...] someStaticMethod ( getClass() ); [...] } >> Because getClass() is final, it didn't occur to me, that he >> would have put up *that* as an example... > Boy, you're spoiling for a fight, ain't'cha, sport? > It's final but it always returns the runtime class, so it is > overridden by the individual subtypes under the hood by special > compiler magic. Actually, I tried to explain, why I was rambling about static methods in response to your example. Now, that you've made your point clearer, namely that getClass() behaves like a virtual method overridden for *every* class, I even understand it. I'm just not yet convinced that this particular pattern, which is already handled by JVM-magic (rather than by the compiler synthesizing those virtual methods), would say "it's good to be able to call overridable non-static methods from a constructor" sufficiently loudly. ;-)