变量
使用var定义变量
var定义变量var t = 'hello world';
t = 1000; // ERROR: A value of type 'int' can't be assigned to a variable of type 'String'使用dynamic和Object定义变量
dynamic和Object定义变量dynamic t;
t = 'hello world';
t = 1000; // NO ERRORdynamic a;
Object b = '';
main() {
a = '';
printLengths();
}
printLengths() {
print(a.length); // NO ERROR
print(b.length); // ERROR: The getter 'length' isn't defined for the type 'Object'
}空安全
终值和常量
Last updated