Why do the courses at Stanford use the lazy initialisation? [duplicate]

北慕城南 提交于 2019-12-07 12:32:01

问题


Why does the course at Stanford use the lazy initialization for all getters?

Is this correct? Does it have any real advantage?

One advantage (for me) is that the init method can become much shorter and you need not check if a variable is allocated.


回答1:


The idea is to load resources on demand. This way everything loads faster and when needed. In the cases it's not used, it doesn't allocate additional memory.



来源:https://stackoverflow.com/questions/21764666/why-do-the-courses-at-stanford-use-the-lazy-initialisation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!