> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart Inequality

The `!=` (inequality) operator is an equality operator that evaluates to `true` if its two operands are not equivalent, and `false` otherwise. In Dart, `!=` is strictly syntactic sugar for the logical negation of the equality operator (`==`).

```dart theme={"dark"}
expression1 != expression2
```

## Underlying Mechanics

Unlike the equality operator (`==`), the `!=` operator **cannot be explicitly overridden** in a Dart class. When the Dart compiler encounters the `!=` operator, it automatically translates the expression into the negated invocation of the underlying `==` evaluation.

The expression `a != b` is evaluated exactly as:

```dart theme={"dark"}
!(a == b)
```

Because of this translation, the behavior of `!=` is entirely dictated by the implementation of the `==` method on the left-hand operand's class, combined with Dart's built-in null handling.

## Evaluation Sequence

When evaluating `a != b`, the Dart runtime resolves the underlying `a == b` expression and negates the result using the following strict sequence:

1. **Null Check:** The runtime first checks both operands for `null`.
   * If both `a` and `b` are `null`, `a == b` yields `true` (causing `!=` to return `false`).
   * If exactly one operand is `null` (e.g., `a` is not `null` but `b` is `null`), `a == b` yields `false` (causing `!=` to return `true`).
2. **Method Invocation:** If and only if neither `a` nor `b` is `null`, the runtime invokes the `==` method on the left-hand operand: `a.==(b)`. The `!=` operator then returns the logical `NOT` (`!`) of the boolean returned by that method.

This sequence ensures that `a.==(null)` is never invoked. This is a fundamental requirement of Dart's sound null safety, as the `==` operator's parameter type is a non-nullable `Object`.

The Dart runtime does *not* automatically perform an identity check (`identical(a, b)`) during this sequence. If an identity check is desired for performance optimization, it must be explicitly implemented by the developer inside the overridden `==` method.

## Syntax Visualization

The following code demonstrates how defining the `==` operator implicitly defines the behavior of the `!=` operator, and illustrates the null-check short-circuiting behavior:

```dart theme={"dark"}
class Entity {
  final int id;

  Entity(this.id);

  // Overriding == automatically provides the logic for !=
  @override
  bool operator ==(Object other) {
    // The identity check is a developer-implemented optimization, 
    // not an automatic runtime step.
    if (identical(this, other)) return true;
    
    return other is Entity && other.id == id;
  }

  @override
  int get hashCode => id.hashCode;
}

void main() {
  Entity entityA = Entity(100);
  Entity entityB = Entity(200);
  Entity entityC = Entity(100);

  // Evaluates as: !(entityA == entityB)
  bool isDifferent = entityA != entityB; // true
  
  // Evaluates as: !(entityA == entityC)
  bool isDifferentValue = entityA != entityC; // false
  
  // Evaluates null checks before method invocation.
  // entityA.== is never invoked because the right operand is null.
  bool isNotNull = entityA != null; // true
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
