Skip to content

Instantly share code, notes, and snippets.

@ulisseshen
Created January 28, 2025 15:27
Show Gist options
  • Save ulisseshen/ce07a7fa4456aabfe64ffa69318f90a2 to your computer and use it in GitHub Desktop.
Save ulisseshen/ce07a7fa4456aabfe64ffa69318f90a2 to your computer and use it in GitHub Desktop.
void main() {
Object obj = "Hello";
print((obj as String).length);
obj = 10;
print((obj as int).isEven);
obj = 10.4;
print(obj.runtimeType);
print(obj.length); // Erro de compilação, precisa de casting. print((obj as String).length);
dynamic dyn = "Hello";
print(dyn.length); // Funciona, mas pode causar erros em runtime.
dyn = 10;
print(dyn.isEven); // Funciona, mas pode causar erros em runtime.
print(dyn.runtimeType); // int
// Causa erros em runtime. [length] não existe no tipo int
print(dyn.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment