is! operator is a binary type test operator used to assert that an object is not an instance of a specified type or any of its subtypes. It evaluates to a bool, returning true if the runtime type of the left-hand operand is incompatible with the type specified on the right-hand side.
Syntax
expression: The variable or expression whose runtime type is being evaluated.Type: The data type (class, mixin, enum, or interface) being checked against.
Operational Semantics
The operator compares the runtime type of theexpression against Type adhering to Dart’s type hierarchy rules.
- Subtype Check: If the runtime type of
expressionis a subtype ofType(includingTypeitself), the operator evaluates tofalse. - Incompatibility: If the runtime type of
expressionis not a subtype ofType, the operator evaluates totrue.
Logical Equivalence
Theis! operator serves as syntactic sugar for the logical negation of the is operator. It improves readability by eliminating the need for parentheses around the type check.
Nullability Rules
The evaluation ofis! differs based on the nullability of the target Type.
- Non-nullable Target (
T):nullis not an instance of a non-nullable type. Therefore,null is! Tevaluates totrue. - Nullable Target (
T?):nullis a valid instance of a nullable type. Therefore,null is! T?evaluates tofalse.
Evaluation Examples
The following code demonstrates the operator’s logic against inheritance hierarchies and null values:Master Dart with Deep Grasping Methodology!Learn More





