dart中的对象运算符
- ?: 条件运算符, 检测 ?. 前面的变量是否存在, 类似ts中的 obj?.name
- as: 类型断言 同 ts中的 str as string
- is: 类型判断, a is int, 判断a是不是int类型
- ..: 级联操作符,可以连续的更改对象内容或调用对象内方法
import './pubilcClass/animal.dart';
class Ract {
int _height = 0;
int _weight = 0;
String name = '';
int age = 0;
Ract(height, weight) {
this._height = height;
this._weight = weight;
}
int jsRact() {
return this._height * this._weight;
}
printNam() {
print('名字${this.name}, 年龄: ${this.age}');
}
}
void main() {
var a1 = new Animal();
a1.setAnimalName('王八');
Ract ra = new Ract(3, 4);
int mj = ra.jsRact();
print(mj);
ra..name = '张三'
..age= 25
..printNam();
}