It is said that hashcode() method of the immutable object is common candidate for the lazy initialization. I think - it is not necessary. if we are considering it true than can anyone explain with logic behind this phrase.
I'm not sure what's meant, but let's think about hashcode on different objects.
On a mutable object we'd want to compute hashcode from the current state. The state could change, so if we stored hashcode in a variable for later use we'd have to recompute it any time something changed. That's wasteful because we might never use hashcode again.
On an immutable object, I suppose we could compute the hashcode the first time somebody asks for it and store it for later use. That may be what was meant by lazy initialization.
Does that make sense?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi