• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

lazy initialization

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

how do i use lazy initialization
how would it change code like this

private int array[];

public void setArray(int arr[])
{
array=arr;
}
public int[] getArray)()
{
return array;
}

help really apprecaited
thanks a lot
barb
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey barb,

I am sorry barb but i couldnt understand what you are trying to do with that code and I didnt understand the term "lazy initialization".
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lazy instantiation/initialisation means you don't initialise a member until the first time that member is requested somewhere.

Typically you'd have something like


Typically it's used when the initialisation of the data is expensive and won't be required for every instance of the class. Using lazy instantiation in such cases yields a performance win for many users of the class either by using less CPU cycles and/or less memory.
 
crispy bacon. crispy tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic