@override of Dart code

Freewind picture Freewind · Jul 9, 2013 · Viewed 13.4k times · Source

I noticed PetitParserDart has a lot of @override in the code, but I don't know how do they be checked?

I tried IDEA dart-plugin for @override, but it has no effect at all. How can we use @override with Dart?

Answer

Alexandre Ardhuin picture Alexandre Ardhuin · Jul 9, 2013

From @override doc :

An annotation used to mark an instance member (method, field, getter or setter) as overriding an inherited class member. Tools can use this annotation to provide a warning if there is no overridden member.

So, it depends on the tool you use.

In the current Dart Editor(r24275), there's no warning for the following code but it should (it looks like a bug).

import 'package:meta/meta.dart';
class A {
  m1() {}
}
class B extends A {
  @override m1() {} // no warning because A has a m1()
  @override m2() {} // tools should display a warning because A has no m2()
}