You must use and this bottle neck:
public synchronized Object getValue() {
    if (_value == null) {
      _value = new ExpensiveObject();
    }
    return value;
 }

Or this:
public Object getValue() {
    if (_value == null) {
       synchronized (this) {
          if (_value == null) {
             _value = new ExpensiveObject();
          }
       }
    }
    return value;
 }

But this is have "issues" and may not work on multi processor systems with
write reordering.

So,
Is it realy needed? :)

"Nathan Brown" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> It would be great if the "Encapsulate fields" refactoring could also
> support lazy initialization when an initialization statement exists at
> the field declaration and the field is of an object type.
>
> Using this option, the existing initialization would be moved into the
> get method so that :
>
> private Object _value = new ExpensiveObject();
>
> would be transformed to
>
> private Object _value;
>
> public Object getValue()
> {
>    if (_value == null) {
>      _value = new ExpensiveObject();
>    }
>    return value;
> }
>
> N.
>


_______________________________________________
Eap-features mailing list
[EMAIL PROTECTED]
http://lists.jetbrains.com/mailman/listinfo/eap-features

Reply via email to