**
1. Static member static method in Dart class
**
Static members in Dart:
1. Use the static keyword to implement class-level variables and functions
2. Static methods cannot access non-static members, and non-static methods can access static members
// class Person {
// static String name = '张三';
// static void show() {
// print(name);
// }
// }
// main(){
// print(Person.name);
// Person.show();
// }
class Person {
static String name = '张三';
int age=20;
static void show() {
print(name);
}
void printInfo(){
/*非静态方法可以访问静态成员以及非静态成员*/
// print(name); //访问静态属性
// print(this.age); //访问非静态属性
show(); //调用静态方法
}
static void printUserInfo(){
//静态方法
print(name); //静态属性
show(); //静态方法
//print(this.age); //静态方法没法访问非静态的属性
// this.printInfo(); //静态方法没法访问非静态的方法
// printInfo();
}
}
main(){
// print(Person.name);
// Person.show();
// Person p=new Person();
// p.printInfo();
Person.printUserInfo();
}
2. Object operators in Dart
Object operators in Dart:
? Conditional operator
as Type conversion
is Type judgment
... Cascade operation (concatenation)
class Person {
String name;
num age;
Person(this.name, this.age);
void printInfo() {
print("${this.name}---${this.age}");
}
}
main() {
// Person p;
// p?.printInfo(); //已被最新的dart废弃 了解
// Person p=new Person('张三', 20);
// p?.printInfo(); //已被最新的dart废弃 了解
// Person p=new Person('张三', 20);
// if(p is Person){
// p.name="李四";
// }
// p.printInfo();
// print(p is Object);
// var p1;
// p1='';
// p1=new Person('张三1', 20);
// // p1.printInfo();
// (p1 as Person).printInfo();
// Person p1=new Person('张三1', 20);
// p1.printInfo();
// p1.name='张三222';
// p1.age=40;
// p1.printInfo();
// Person p1 = new Person('张三1', 20);
// p1.printInfo();
// p1
// ..name = "李四"
// ..age = 30
// ..printInfo();
}