跳转至

运算符重载

operatorDemo() {
  OperatorClass op1 = OperatorClass(18);
  OperatorClass op2 = OperatorClass(32);
  print(op1 > op2);
}

class OperatorClass {
  int age;
  OperatorClass(this.age);
  bool operator >(OperatorClass other) => this.age > other.age;
}

运算符

??= ??

  var a;
  a ??= 10; //a为空 则a赋值10,a有值则直接返回
  a ??= 13;

  var b;
  b = 5;
  print(b ?? a); //??如果左边有值返回左边,没有就返回右边