author avatar

sujay

Tue Dec 19 2023

Difference between dynamic and Object type in dart dynamic : dynamic is incredibly flexible. It tells Dart compiler to skip the type checking at compile time while type checking happens at run time. This is helpful when working with data of uncertain types.


dynamic value = 42;
value = 'Sujay';
print(value.isEven); // Error thrown during runtime

Object : Object is the root class for all other classes. Its like a container like that can hold any value. Since Object is generic, you won't have access to specific methods or properties of value without type casting


Object value = 42;
print(value.isEven); // throws compile time error