Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.westnet.com.au!news.westnet.com.au.POSTED!not-for-mail NNTP-Posting-Date: Wed, 29 Jun 2011 04:57:26 -0500 From: "Qu0ll" Newsgroups: comp.lang.java.programmer Subject: Automatic linking of related objects in constructor Date: Wed, 29 Jun 2011 19:56:49 +1000 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 15.4.3508.1109 X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3508.1109 Message-ID: Lines: 18 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 124.171.45.138 X-Trace: sv3-LRnwBjHLO9H15xHvI/+Q1la0HZ9FiXu9vdhKovEU37KItkLscxPU+ysuuZn2ee0Vk4ZclYQJpRvbxl/!IbFfU+GfRXxpRaanA8QBl+zE6Fv2HxPKM7ENfU7pcwj0xJee6h/XHvt+DU39O8aqMrISchBQUho3!GxsunrJYPKVngugVfv+hSQ== X-Complaints-To: abuse@westnet.com.au X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2016 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5769 Suppose you have class A which contains a list of objects of class B and that the constructor for B takes in a reference to the A object which is to include it in said list. Is it safe to make a call to A's method addB(B b) in that B constructor passing in "this"? I have heard that it's bad practice to "leak" a reference to an object from within its own constructor because it may be in an invalid state. If not, how else can I automatically add the B object to the list in A without forcing the client programmer to explicitly call addB() given that they have already passed in the B as an argument? And loving it, -Qu0ll (Rare, not extinct) _________________________________________________ Qu0llSixFour@gmail.com [Replace the "SixFour" with numbers to email me]