This example defines a hierarchy of three classes called Food, RecipeIngredient, and ShoppingListItem,and demonstrates how their initializers interact.
静态工厂和构造器有个共同的局限性:它们都不能很好地扩展到大量的可选参数。
Static factories and constructors share a limitation, they do not scale well for large number of optional parameters.
类型构造器list(seq)可将任意序列或可迭代对象转换为具有相同排列顺序的相同条目的列表。
The type constructor list(seq) converts any sequence or iterable into a list with the same items in the same order.
Food类引入了一个叫做name的String类型属性,并且提供了两个构造器来创建Food实例:.
Single String property called name and provides two initializers for creating Food instances:.
静态工厂和构造器有个共同的局限性:它们都不能很好地扩展到大量的可选参数。
Static factories and constructors have a limitation; they do not scale very well when there a large number of optional parameters.
Person()构造器定义了'this'指针,指向了其实例本身.
The Person() constructor defines'this' as an instance of itself.
The Food class introduces a single String property called name andprovides two initializers for creating Food instances:.
编程人员通常知道如何避开这一限制:通过提供两个构造器,它们的参数列表只在参数类型的顺序上有所不同。
Programmers have been known to get around this restriction by providing two constructors whose parameter lists differ only in the order of their parameter types.
It introduces an Int property called quantity(in addition to the name property it inherits from Food)and defines two initializers for creating RecipeIngredient instances:.
注意:你无法在不使用'new'关键字的情况下,在Strict模式下从构造器创建一个新的对象。
Note: You will notbe able to create a new object from constructor in strict mode without using‘new' keyword.
中文
Bahasa indonesia
日本語
عربى
Български
বাংলা
Český
Dansk
Deutsch
Ελληνικά
Español
Suomi
Français
עִברִית
हिंदी
Hrvatski
Magyar
Italiano
Қазақ
한국어
മലയാളം
मराठी
Bahasa malay
Nederlands
Norsk
Polski
Português
Română
Русский
Slovenský
Slovenski
Српски
Svenska
தமிழ்
తెలుగు
ไทย
Tagalog
Turkce
Українська
اردو
Tiếng việt