Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding Instance creation  RSS feed

 
praveen raaj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
Can you please explain me, what is difference between eagerly created instance and lazily created instance?and which one is better solution?

please correct me if i'm wrong?
 
Campbell Ritchie
Marshal
Posts: 55681
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Asking which is the better solution is a bit like asking whether a boat or a bicycle is better. The answer depends on whether there is a road or a river . . .
So it depends on the circumstances which is better. There should be a little about that in Bloch's Effective Java and probably other books.

Eager initialisation:Lazy initialisation:You see f is only instantiated when it is used. In the eager example, f was instantiated immediately.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!