It might be worth noting that in my 2008 copy of the book the code you
posted is slightly different (changes are bold) but the difference
is significant, since it exposes the "this" parameter to external
code:
public EventListener(EventSource eventSource){
eventSource.registerListener(this);
}
Since final "x'
must be initialized somewhere or the code will not
compile, we must assume it's initialized but that initialization
is not shown. (Unfortunately, as that makes this a bad example
since x is the focus!)
I think the book is still correct because the only
guarantee you have about the event listener object is that when
the constructor has completed, the following 2 things have been
done:
A) a value was written to x
B) the "this" parameter was written into eventSource's collection of listeners.
BUT there is is no guarantee they are implemented in this order! If B happens first,
then another thread may end up seeing the object before the constructor
has finished A, and the wrong value of x is possible.
chris