Flutter 抽象类也能实例化

5 min read

Flutter 抽象类也能实例化

main(List<String> args) {
  final s = Shape();

  final map = Map();
  print(map.runtimeType);
}


abstract class Shape {
  int getArea();
  String getInfo() {
    return "形状";
  }

  factory Shape() {
    return null;
  }
}

Flutter 抽象类其实是不能实例化的, 但是可以通过抽象类里面的工厂构造函数返回一个他的子类变相实现实例化