operator(重载符)
class Person {
var age;
Person(var age) {
this.age = age;
}
### 重载可以自定义==,-等等
operator +(p) => new Person(age + p.age);
}
main() {
Person p = new Person(10);
Person p2 = new Person(20);
print((p + p2).age);
}
//print(30)
with(多继承)
class a {
eat() {
print("111");
}
}
class b {
eat2() {
print("222");
}
}
class c with a, b {}
main() {
new c().eat();
new c().eat2();
}
导入优化
import 'package:stack1.dart' as stack1;
import 'package:stack2.dart' as stack2;
------------------------
import 'stack1.dart' show pop,push;
import 'stack2.dart' hide pop,push;
---------------------------
import 'stack1.dart' as stack1 show pop,push
-----------------
##延迟导入
import ‘xxx.dart’ deferred as xxx;
导出
export 'xxx.dart' show xxxx;
级联
"Hello".length.toString();//值为5
"Hello"..length.toString();//值为Hello
变种
var address=new Address.of("xxx)";
address.set(“xxxx”);
address.state="xxx";
new Address.of("xxx")
..set("xxx")
..state=“xxxx”
assert
factorial(int x){
return x==0?1:x*factorial(x-1);
}
如果传入-1就死循环
factorial(int x){
assert(x>=0);
return x==0?1:x*factorial(x-1);
}
等同于
factorial(int x){
if(x<0)throw new AssertionError();
return x==0?1:x*factorial(x-1);
}