gpt4 book ai didi

flutter - 我可以向下转换一个类,使它丢失原始的构造函数吗?

转载 作者:行者123 更新时间:2023-12-03 04:35:56 26 4
gpt4 key购买 nike

  • dartpad
  • 上运行以下代码

    class Foo {
    const Foo(this.message);
    final String message;
    }

    class Bar extends Foo {
    const Bar(String message, this.another,) : super(message);
    final String another;
    }

    void main() {
    const Foo _foo = Bar('hello','world');
    const Bar _bar = _foo;
    print(_bar.another);
    }

    撰写本文时,使用darpad Based on Flutter 1.22.0-12.1.pre Dart SDK 2.9.3

  • 输出是world

  • 这是我们在每个 Widget中遇到的典型行为,
    但是有一种方法可以迫使对象丢失“额外的”构造函数
    ,而不重铸整个对象吗?

    最佳答案

    如果没有人打电话,它会因摇树而消失。

    关于flutter - 我可以向下转换一个类,使它丢失原始的构造函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64122402/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com