Dart:如何实现类似的情况,例如“当hashcode()被覆盖时,==()也应被覆盖"?

编程入门 行业动态 更新时间:2024-10-22 09:41:00
本文介绍了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()被覆盖时,==()也应被覆盖"?

本文发布于:2023-11-08 07:42:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:被覆   也应   如何实现   类似   情况

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!