>
> It's still uncomfortable though that there is a lot of code out there
> of this form that will surely remain broken -- with JavaBeans and
> other frameworks, you are not allowed to declare write-once fields as
> final since you must have a no-arg constructor, so there is no good
> way for people to take advantage of rules for finals.
>
I don't know a lot about beans, but couldn't you write the value for the
final into a static data structure before you invoke the constructor?
Then the constructor could read the static data into a final field...
To keep it thread-safe, you can have the static data structure be a
mapping from thread ids to the object in question...
To my way of thinking, that is only slightly uglier than setter methods.
It would look, to the user, like:
Foo.setNextBar(new Bar());
Foo f = new Foo();
Of course, this could be horrible and ill-informed speculation on my part.
Jeremy
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:27 EDT