Object is the root class of the non-nullable Dart class hierarchy. Every other non-nullable class in Dart extends Object, either directly or recursively. Consequently, any non-nullable value can be assigned to a variable of type Object.
Type Hierarchy and Null Safety
In Dart’s sound null safety system, the top of the type hierarchy is structured as follows:Object?: The root of the entire type hierarchy, encompassing all types includingNull.Object: The root of all non-nullable types. It corresponds to the non-nullable subset ofObject?.
extends clause, it implicitly extends Object.
Instance Members
TheObject class defines a minimal set of properties and methods available to all non-nullable Dart instances.
| Member | Type | Description |
|---|---|---|
hashCode | int | A hash code derived from the object. By default, this represents the internal identity of the object. |
runtimeType | Type | A representation of the runtime type of the object. |
toString() | String | Returns a string representation of the object. The default implementation returns Instance of 'ClassName'. |
operator == | bool | Checks equality. The default implementation checks for referential equality (identity). |
noSuchMethod(Invocation invocation) | dynamic | Invoked when a non-existent method or property is accessed on the object (primarily used with dynamic dispatch). |
Equality Semantics
The default behavior of the equality operator (==) in the Object class is identity comparison. It returns true only if both references point to the exact same instance in memory. Subclasses often override this operator to provide structural equality.
Static Typing vs. dynamic
While Object permits the assignment of any non-nullable value, it enforces strict static type checking. Unlike the dynamic type, which disables static checking to allow arbitrary member access, a variable typed as Object only permits access to the members defined in the Object class itself (toString, hashCode, etc.).
Constructors
TheObject class provides a constant constructor. This enables subclasses to define const constructors, allowing for the creation of compile-time constants.
Master Dart with Deep Grasping Methodology!Learn More





