当前位置:网站首页>Dart 扩展特性
Dart 扩展特性
2022-06-30 12:56:00 【xiangxiongfly915】
Dart 扩展特性
概述
一般情况下要扩展一个类,需要继承这个类,在dart 2.7以后,引入extension,用来对类的方法进行扩展。
使用
extension StringToNumber on String {
int toInt() {
return int.parse(this);
}
}
extension NumberOperator on int {
int add(int other) {
return this + other;
}
}
int result = "18".toInt();
int sum = 1.add(2);
API冲突
方式一
使用show或hide限制使用。
import 'extension1.dart' hide StringToNumber, NumberOperator;
import 'extension2.dart';
方式二
重命名。
import 'extention1.dart';
import 'extention2.dart' as ext2;
边栏推荐
- Hangzhou E-Commerce Research Institute: the official website (website) is the only form of private domain
- golang文件的写入、追加、读取、复制操作:bufio包的使用示例
- How can c write an SQL parser
- Multi terminal collaboration of Huawei accounts to create a better internet life
- Basic syntax of unity script (1) - common operations of game objects
- postman 自動生成 curl 代碼片段
- Knowledge dissemination cannot replace professional learning!
- Clearing TinyMCE rich text cache in elementui
- Idea 2021.3 golang error: rning: undefined behavior version of delve is too old for go version 1.18
- 【系统分析师之路】第五章 复盘软件工程(软件过程改进)
猜你喜欢

SQL attendance statistics monthly report

Read all the knowledge points about enterprise im in one article

postman 自动生成 curl 代码片段

今日睡眠质量记录80分

Dark horse notes - collection (common methods and traversal methods of collection)

数据湖(十一):Iceberg表数据组织与查询

资源变现小程序开通流量主教程

Machine learning notes - Introduction to autocorrelation and partial autocorrelation

SQL考勤统计月报表

逆向调试入门-PE中的VA与RVA换算04/07
随机推荐
数据湖(十一):Iceberg表数据组织与查询
How can I protect my private key?
JMeter learning notes
ABAP工具箱 V1.0(附实现思路)
Matlab tips (22) matrix analysis -- stepwise regression
【C】 In depth understanding of pointers and callback functions (Introduction to simulating qsort)
Introduction to the renewal of substrate source code: the pledge amount is greatly reduced, and rocksdb can be completely disabled
golang文件的写入、追加、读取、复制操作:bufio包的使用示例
Basic syntax of unity script (5) - vector
今日睡眠质量记录80分
[deep anatomy of C language] storage principle of float variable in memory & comparison between pointer variable and "zero value"
Apache Doris Compaction优化百科全书
(8)JMeter元件详解之 Once only Controller 仅一次控制器
Idea 2021.3 golang error: rning: undefined behavior version of delve is too old for go version 1.18
防火墙基础之总部双机热备与分支基础配置
Basic syntax of unity script (4) - access to other game objects
How does MySQL merge columns?
SQL programming problem, test case failed
Observable, reliable: the first shot of cloudops series Salon of cloud automation operation and maintenance
Ffmpeg miscellaneous