我有两个类A和B扩展A。
class A{
String a;
A();
}
class B extends A{
String b;
B();
}
如何获得赞:B getA(){
return A();
}
或 B b = A();
我的代码: Future<B> getB() async {
return apiMethod("url", headers: {'requirestoken': true}, httpEnum: HttpEnum.GET).then((response) {
return B.fromJson(response.data);
}).catchError((error, stacktrace) => A.catchErrorMethod(error, stacktrace));
}
而A类 class A {
A.catchErrorMethod(error, stacktrace):....
}
最佳答案
你不可以做这个。
B是A,但A不是B。
但是,您可以像在A一样随处使用B
关于class - 如何在Dart中将父类转换为子类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64556498/