1)条件运算符 ?.
void main() {
Person person = new Person();
person?.work();
}
class Person {
String name;
int age;
void work() {
print("Work...");
}
}
运行结果:
Work...
2)类型转换:as
void main() {
var person;
person = "";
person = new Person();
(person as Person).work();
}
class Person {
String name;
int age;
void work() {
print("Work...");
}
}
运行结果:
Work...
3)是否指定类型:is 、 is!
if (person is Person) {
person?.work();
}
4)级联操作:..
Person person = new Person();
person
..name = "Tom"
..age = 10
..work();