Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of putting @override in my PolymerDart methods, when it works without?

In terms of creating classes which involve inheritance, some actually need the annotation of override. When working with PolymerDart though, specifically

@override
attached(){...}

I see no reason why i need it. It works as expected without it.

Since it is just an annotation, is it just for Developers to see so they understand that function is overriding some other function?

My bet is that it is just for developers, and unlike other annotations which carry out some sort of execution, these do not.

like image 447
Fallenreaper Avatar asked Mar 21 '17 14:03

Fallenreaper


1 Answers

If you enable the linter rule annotate_overrides the DartAnalyzer provides hints

  • for members that override other members of superclasses or interfaces, but don't have the @override annotation
  • for members that have the @override annotation, but don't actually override other members of superclasses or interfaces.

The @override annotation is helpful if it is used consistently, because it shows when a member is an override.
The linter rule ensures that it is used consistently.

There is also the `overridden_fields lint, but AFAIK this is going to be deprecated because. This was forbidden until recently in Dart Development compiler but this restriction was removed. I don't know if it is still discouraged, but there are cases where it makes sense and therefore I think the linter rule shouldn't be used anymore because it is prone to cause hints for valid code.

like image 176
Günter Zöchbauer Avatar answered Oct 05 '22 06:10

Günter Zöchbauer