プロのインターネット中毒者 • ゲーム愛好家 • 技術クリエイター
プロのインターネット中毒者 • ゲーム愛好家 • 技術クリエイター

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の最新動画をチェック!

    ライブ配信にリアルタイム字幕を簡単に追加する方法