Created
January 28, 2025 15:27
-
-
Save ulisseshen/ce07a7fa4456aabfe64ffa69318f90a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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