Dart: How to implement a similar situation like “when hashcode() is overridden, ==() should also be overridden”?

♀尐吖头ヾ 提交于 2021-02-20 04:08:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!