延迟初始化的主要弊端是,由于要查看属性是否已定义,如果没有,则得到它的值,这会使代码变得更复杂。
The main disadvantage of lazy initialization is your code becomes more complex because you need to check to see if the attribute has been defined yet and, if not, obtain its value.
延迟初始化的主要缺点是:代码将变得更复杂,因为需要查看是否定义了属性,如果还未定义,则要获取属性值。
The main disadvantage of lazy initialization is that your code becomes more complex because you need to check to see if the attribute has been defined yet and, if not, obtain its value.
这两者都体现了延迟初始化的特性(因此又被称为futures)。前者是一个类,而后者则是一个轻量的,但并非“绝对”线程安全的结构。
Both support the idea of deferred initialization, also known as futures, the former is a class and the later a lightweight and slightly less safe structure.
应用推荐