Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Effective Java

 
surya.raaj prakash
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I could not understand some parts(i.e Bold Text) of the Effective Java of item 71 it says,

Lazy initialization is the act of delaying the initialization of a field until its
value is needed. If the value is never needed, the field is never initialized. This
technique is applicable to both static and instance fields. While lazy initialization
is primarily an optimization, it can also be used to break harmful circularities in
class and instance initialization


Thanks & Regards,
Surya.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose this is your class(DTO)



if user enter the value for usdf ,then only you plan to create a object for UserDefinedField[using Factory method getUserDefinedField()] and want to set the value. otherwise(if user ignore the UserDefinedField ) there is no need for creating an Object for usdf.

Getting my explaination ?
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure, but I think circularity in class initialization would occur if initialization of one class(say A) depends on initialization of other(say B) and at the same time initialization of the other class(B) depends on initialization of the first class(A). The dependency graph will have a loop. Typically, class initialization is the process of loading the class in memory and then initializing the static variables of the class to their values.


 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy, shouldn't there be a != null test somewhere in that method. Otherwise you will return a different value every time the method is called.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the *particularly* lazy-initialization approach.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:It's the *particularly* lazy-initialization approach.
Touche
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
surya.raaj prakash, have you checked the Bloch05 reference given in Effective Java?
 
surya.raaj prakash
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell Ritchie,
Thanks For Your Reply,

Campbell Ritchie wrote:surya.raaj prakash, have you checked the Bloch05 reference given in Effective Java?

Yes,I have checked. you mean Java Puzzlers By Joshua Bloch, Neal Gafter Right?
And This is an excellent Books,again thank you cambell...for given the great reference
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic