instead of placing warnings blah blah, why dont we leave the functionality
as is and add this lazy initiaslization code later whena (if at all) needed.
It's not rocket science and at leasty in my projects I don't have many
places where I would benefit from lazy initialization.

-- dimiter

BTW it reminds me of the pattern wizards form TogetherJ - cute, but not very
usefull..


"Nathan Brown" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> There are infinite choices about how synchronization can be acheived;
> here you have only shown synchronization on 'this', but of course any
> object can be used to synchronize on.
>
> So there is no way the IDE can make a choice about the synchronization
> mechanism to use, therefore it should just leave it out, and trust the
> developer to put in the correct synchronization at the necessary points.
>
> Maybe a comment should be placed in the get method '// WARNING - not
> thread safe!' for any novice users who think that IDEA is going to do
> their job for them ;)
>
> Alexey Efimov wrote:
> > 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