当前位置:网站首页>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;
边栏推荐
- 可观测,才可靠:云上自动化运维CloudOps系列沙龙 第一弹
- Common UI components
- rxjs Observable 两大类操作符简介
- 华为帐号多端协同,打造美好互联生活
- How can I protect my private key?
- Kubeedge's core philosophy
- RK356x U-Boot研究所(命令篇)3.2 help命令的用法
- Simple understanding of the difference between get request and post submission
- Lucky hash quiz system development (source code deployment) fun investment hash game play development (case requirements)
- MySQL access denied, opened as Administrator
猜你喜欢

WTM major updates, multi tenancy and single sign on

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

postman 自動生成 curl 代碼片段

写信宝小程序开源

Open source of xinzhibao applet

On the simplification and acceleration of join operation

Basic syntax of unity script (1) - common operations of game objects

DeFi“钱从哪来”?一个大多数人都没搞清楚的问题

Rk356x u-boot Institute (command section) 3.2 usage of help command

MySQL access denied, opened as Administrator
随机推荐
golang基础 —— 切片几种声明方式
Assertions of regular series
Lucky hash quiz system development (source code deployment) fun investment hash game play development (case requirements)
ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accurately
这个编辑器即将开源!
60 divine vs Code plug-ins!!
【刷题篇】供暖器
Motor control Clarke( α/β) Derivation of equal amplitude transformation
[deep anatomy of C language] storage principle of float variable in memory & comparison between pointer variable and "zero value"
In line with the trend of media integration, Zhongke Wenge and Meishe jointly create digital intelligence media publicity
Clearing TinyMCE rich text cache in elementui
Apache Doris Compaction优化百科全书
资源变现小程序开通流量主教程
知识传播不能取代专业学习!
Derivation of Park transformation formula for motor control
Knowledge dissemination cannot replace professional learning!
Understanding and mastery of ffmpeg avbufferpool
Basic syntax of unity script (4) - access to other game objects
golang基础 —— 切片和数组的区别
Unity animator parameter