Dart:如何实现类似的情况,例如“当hashcode()被覆盖时,==()也应被覆盖"? [英] Dart: How to implement a similar situation like "when hashcode() is overridden, ==() should also be overridden"?

查看:59
本文介绍了Dart:如何实现类似的情况,例如“当hashcode()被覆盖时,==()也应被覆盖"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在类中重写hashCode()或==运算符时,飞镖分析器将发出警告,表示另一个方法也应被重写.

When either hashCode() or == operator is overridden in a class, the dart analyzer warns, saying that the other method should also be overridden.

我可以在其他方法上实现类似的情况吗?还是Dart Analyzer提供的特殊功能?

Can I implement a similar case on other methods? Or is this feature a special case provided by Dart Analyzer?

例如,

class A {
  void method1() {}

  void method2() {}
}

class B extends A {
  @override
  void method1() {}
}

在这一点上,我想发出一个警告,指出B类也应该覆盖method2().有可能吗?

At this point I want to produce a warning that class B should also override method2(). Is that possible?

推荐答案

您看到的是一条短绒规则.飞镖分析器实现了许多这样的功能,您可以在此处进行查看,或仅查看该特定规则.
尽管您可以为您的项目自定义静态分析,但据我所知,定制的掉毛规则仍然不可用(至今).

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).

这篇关于Dart:如何实现类似的情况,例如“当hashcode()被覆盖时,==()也应被覆盖"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆