> I believe you can't safely publish the "this" (e.g. Bar) from inside > its constructor, meaning you can't do (in Bar's constructor) foo = new > Foo(this); this ends up (in my mind) reducing the usability of the > technique. See JCIP, chapter 3, "Sharing Objects", "Safe Construction > Practices"
Is it such a black-and-white scenario? I would have thought there were a few caveats with which publishing 'this' in the constructor is safe. So within either object's constructor the following should hold: - foo = new Foo(this) is called last, after the state of the object has been setup - Foo does not publish Bar - Foo does not mutate Bar - Bar does not publish Foo within the constructor I've not read the reference you gave though, so I expect I'm missing something, but I'd be surprised if there were no conditions under which passing 'this' into a composed object in the constructor is unsafe. Kind regards, Graham -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
