Group: errors

Maturity: stable

Dart SDK: >= 2.0.0 • (Linter v0.1.11)

Since info is static, may be stale
fluttereffective dart

View all Lint Rules

Using the Linter

DO override hashCode if overriding == and prefer overriding == if overriding hashCode.

Every object in Dart has a hashCode. Both the == operator and the hashCode property of objects must be consistent in order for a common hash map implementation to function properly. Thus, when overriding ==, the hashCode should also be overridden to maintain consistency. Similarly, if hashCode is overridden, == should be also.


class Bad {
  final int value;

  bool operator ==(Object other) => other is Bad && other.value == value;


class Better {
  final int value;

  bool operator ==(Object other) => other is Better && other.value == value;

  int get hashCode => value.hashCode;