In the flutter documentation the keyword @override is used a lot in classes. I tried to search for the meaning but still can't understand. What is the purpose of this @override Keyword.
Note: I come from a JavaScript background.
The annotation @override marks an instance member as overriding a superclass member with the same name. The annotation applies to instance methods, getters and setters, and to instance fields, where it means that the implicit getter and setter of the field is marked as overriding, but the field itself is not.
The @Override annotation indicates that the child class method is over-writing its base class method. It extracts a warning from the compiler if the annotated method doesn't actually override anything. It can improve the readability of the source code.
In any case, the use of @override is optional. For example, the annotation is intentionally not used in the Dart platform libraries, since they only depend on themselves.
Method overriding occurs in dart when a child class tries to override the parent class's method. When a child class extends a parent class, it gets full access to the methods of the parent class and thus it overrides the methods of the parent class.
@override
just points out that the function is also defined in an ancestor class, but is being redefined to do something else in the current class. It's also used to annotate the implementation of an abstract method. It is optional to use but recommended as it improves readability.
The annotation @override marks an instance member as overriding a superclass member with the same name.
https://api.dartlang.org/stable/1.24.3/dart-core/override-constant.html
JavaScript also supports @override
as an annotation, but it has to be in a comment. http://usejsdoc.org/tags-override.html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With