Reputation: 1
void main(){
new C(new A()); // This gives no warning or error
new D(new A()); // This gives an error
}
class A{}
class B extends A{}
class C {
B b;
C(A bb){ this.b = bb; }
}
class D {
B b;
D(this.b);
}
In both statements in main function I give as a parameter an instance of type A. If I am not wrong both statements should give an error or warning in Strong mode, however only the second gives an error: Type check failed: new A()(A) is not of type B
Image showing the code compiled from https://dartpad.dartlang.org/
I just started learning dart language and I couldn't find in the documentation an explanation for this case. Does anybody know why this is happening?
Upvotes: 0
Views: 84
Reputation: 76233
It looks like you made a typo in your C
constructor. Do you mean:
class C {
B b;
C(B/*not A*/ bb){ this.b = bb; }
}
Upvotes: 1