is
is 關(guān)鍵字為類型檢查關(guān)鍵字
重寫==
下面案例運(yùn)用了is關(guān)鍵字,檢查類型,并以判斷屬性值是否相等來檢查對象是否相等。
class Student{
String name;
int age;
String school;
Student.create(this.name,this.age,this.school);
@override
bool operator ==(other) {
// 判斷是否是非
if(other is! Student){
return false;
}
final Student student = other;
return name == student.name
&& age == student.age
&& school == student.school;
}
}
void main(){
Student studentA = Student.create('小白', 18, '南京大學(xué)');
Student studentB = Student.create('小白', 18, '南京大學(xué)');
print(studentA == studentB);
// true
}