I anticipated a compile-time error when overriding a method in Dart without the correct (to my knowledge so far) return type. However, things seem to be different when the return type of the method is void
:
abstract class AbstractClass { void methodDoesNotReallyReturnVoid(); } class ConcreteClass extends AbstractClass { // NO ERROR here! @override int methodDoesNotReallyReturnVoid() => 12; } void main() { print(ConcreteClass().methodDoesNotReallyReturnVoid()); // hm...? }
The code above compiles without complaints and prints the integer as expected though I did not properly override that method like, for example, in Java.
May I know what is distinct about "void" here?
from Recent Questions - Stack Overflow https://stackoverflow.com/questions/65370922/method-overriding-in-dart-when-the-return-type-is-void Ardent Coder http://ifttt.com/images/no_image_card.png
没有评论:
发表评论