[concurrency-interest] Good terminology for setting up effectively immutable objects?

Mark Thornton mthornton at optrak.co.uk
Wed Apr 30 09:52:41 EDT 2008


Matthias Ernst wrote:
> Having said that, I love final fields and I've been dreaming about a
> way to have _clients_ initialize blank final fields. Something like:
>
> X x = new X() {{
>  foo = bar;
> }};
>
>   
class X {
    final Type foo; ...
   private X(Builder b) {
       foo = b.foo;
    }

  static class Builder {
     protected Type foo;

    public X create() {return new X(this);}
  }
}


...

X x = new X.Builder() {
    public X create() {
       foo = bar;
       return super.create();
    }.create();


No doubt a shorter version is possible.

Mark


More information about the Concurrency-interest mailing list