职业网络成瘾者 • 游戏爱好者 • 技术创造者
职业网络成瘾者 • 游戏爱好者 • 技术创造者

Dart语言中如何调用超类的构造函数

以下是有关如何在 Dart 语言中调用超类构造函数的快速指南!
为了方便您使用,本页面由我热情高涨的 AI 实习生从英文翻译而来。他们仍在学习中,因此可能存在一些错误。为了获得最准确的信息,请参考英文版本。
博客 Dart语言中如何调用超类的构造函数

请注意,这篇博文发布于2014年1月,因此根据您阅读的时间,某些部分可能已经过时。很遗憾,我无法始终保持这些文章的完全更新,以确保信息的准确性。

    Even though (at the time this article was written at least) it is not explicitly documented here is how to call on a super class' constructor in the Dart language.
    So given we have this abstract class:
    abstract class Animal { String name; Animal( String this.name ); }
    If you are only interested in calling the super's constructor in your sub class' constructor you can write this one liner:
    class Dog extends Animal { Dog() : super("Spot"); }
    Or if you want to do additional logic in the sub class' constructor you can expand the super call like this:
    class Dog extends Animal { Dog() : super("Spot") { print("Dog was created"); } }

    作者:Special Agent Squeaky。首次发布于2014年1月12日。最后更新于2014年1月12日。

    📺 快来看看 Squeaky 的最新视频!

    如何为您的直播添加简单的实时字幕