Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有这种情况:
class Foo { final _bar; Foo([bar = 'hello']); }
_bar在 Dart 中,鉴于它是私有的,我该如何初始化?
_bar
您可以使用初始化列表。
class Foo { final _bar; Foo([bar = 'hello']) : _bar = bar; }
初始化列表在构造函数主体之前运行。