问题
When either hashCode() or == operator is overridden in a class, the dart analyzer warns, saying that the other method should also be overridden.
Can I implement a similar case on other methods? Or is this feature a special case provided by Dart Analyzer?
For exmaple,
class A {
void method1() {}
void method2() {}
}
class B extends A {
@override
void method1() {}
}
At this point I want to produce a warning that class B should also override method2(). Is that possible?
回答1:
What you are seeing is a linter rule. The dart analyzer implements a bunch of these which you can view here or check out just that specific rule.
While you can customize static analysis for your project, as far as I can tell support for custom linting rules is still not available (yet).
来源:https://stackoverflow.com/questions/64255267/dart-how-to-implement-a-similar-situation-like-when-hashcode-is-overridden