Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: calling own methods from constructor Date: Thu, 07 Apr 2011 17:38:23 -0600 Organization: As little as possible Lines: 27 Message-ID: <2psjtt639s.fsf@shell.xmission.com> References: <2011040622233261380-angrybaldguy@gmailcom> <2pzko2f2nx.fsf@shell.xmission.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="PnllQd880uOddfy6hsxHuQ"; logging-data="16850"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VCYhiYUtFsgzwoNXwZCqu" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:LjnF5jRRr4n6nXwbW0sXqB66jmA= sha1:VK5rB6OLJVYqu9xhY7pXni45JbA= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2956 Tom Anderson writes: >> In effect, until the constructor of Foo completes, the object is >> considered to be an instance of Foo, so calls to virtualMethod() to >> to Foo.virtualMethod even if it has been overridden. After the >> super constructor completes, the object is treated as an instance of >> Bar, so evaluating new Bar().virtualMethod() would print two lines >> and then throw an exception. > > I recoil in horror. It's surprised me more than once. You'd think after the first time I would remember, but no... > >> I've been surprised by this behaviour in C++ enough times that I'm >> not sure that it has the better approach. But a solution does >> exist. > > That's slightly like solving toothache by amputating your head. C++ is an interesting language. The interesting languages aren't always the ones you want to do actual work in. -- Jim Janney