aspose file tools*
The moose likes Java in General and the fly likes Doubt in Effective Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Doubt in Effective Java " Watch "Doubt in Effective Java " New topic
Author

Doubt in Effective Java

surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Oct 12, 2008
Posts: 1369
    
    1

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.



[List of FAQs] | [Android FAQ] | [Samuh Varta]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
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

Joined: Sep 29, 2008
Posts: 12617

It's the *particularly* lazy-initialization approach.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
David Newton wrote:It's the *particularly* lazy-initialization approach.
Touche
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
surya.raaj prakash, have you checked the Bloch05 reference given in Effective Java?
surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
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
 
Don't get me started about those stupid light bulbs.
 
subject: Doubt in Effective Java