!=) is a relational operator that evaluates the distinction between two objects. It returns a bool value of true if the operands are not equal and false if they are equivalent.
Syntax
Operational Semantics
In Dart, the!= operator is syntactic sugar for the negation of the equality operator (==). It cannot be explicitly overridden in a class definition. Its behavior is strictly defined as:
!= relies entirely on the implementation of == on the left-hand operand, the definition of “inequality” depends on whether the object performs referential equality or value equality.
1. Referential Inequality (Default)
By default, classes inherit the== implementation from Object, which compares memory references (identity). The != operator returns true if the operands exist at different memory addresses, even if their internal state is identical.
2. Value Inequality
If a class overrides the== operator (and the hashCode getter), the != operator evaluates inequality based on the logical content of the objects.
Null Handling
The!= operator adheres to standard null safety rules regarding identity:
- Comparing any non-null object to
nullreturnstrue. - Comparing
nulltonullreturnsfalse.
Static Analysis and Type Safety
The Dart analyzer performs static checks on equality expressions. If the operands are of unrelated types (types that are disjoint and cannot possibly be equal), the analyzer issues a warning. Since the underlying== check is guaranteed to return false for unrelated types, the != operation is guaranteed to return true.
Master Dart with Deep Grasping Methodology!Learn More





