当前位置:网站首页>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;
边栏推荐
- Apache Doris Compaction优化百科全书
- Motor control Clarke( α/β) Derivation of equal amplitude transformation
- Basics of golang -- the difference between slicing and array
- Rk356x u-boot Institute (command section) 3.2 usage of help command
- 服务线上治理
- Mqtt ROS simulates publishing a custom message type
- rxjs Observable 两大类操作符简介
- Exlipse operates on multiple rows at the same time. For example, input the same text in multiple lines and columns at the same time
- Simple understanding of the difference between get request and post submission
- Golang foundation -- slicing several declaration methods
猜你喜欢

Postman automatically generates curl code snippets

There is no utf8 option for creating tables in Navicat database.

App wechat payment unicloud version of uniapp payment (with source code)

This article explains the concepts of typed array, arraybuffer, typedarray, DataView, etc

华为帐号多端协同,打造美好互联生活

jmeter 学习笔记

这个编辑器即将开源!

Open source of xinzhibao applet

损失函数:DIOU loss手写实现

QT read / write excel--qxlsx worksheet display / hide status setting 4
随机推荐
资源变现小程序开通流量主教程
Goods and services - platform properties
DNS 解析之家庭网络接入 Public DNS 实战
All the abnormal knowledge you want is here
Dark horse notes - collection (common methods and traversal methods of collection)
波卡跨链通信源码探秘: 要素篇
Wechat applet reports an error: typeerror: cannot read property 'SetData' of undefined
发生QQ大规模盗号事件,暴露出什么网络安全问题?
SQL编程问题,测试用例不通过
On the simplification and acceleration of join operation
In line with the trend of media integration, Zhongke Wenge and Meishe jointly create digital intelligence media publicity
腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
Mqtt ROS simulates publishing a custom message type
Loss function: Diou loss handwriting implementation
可觀測,才可靠:雲上自動化運維CloudOps系列沙龍 第一彈
VisualStudio and SQL
Kubeedge's core philosophy
一次 Keepalived 高可用的事故,让我重学了一遍它!
get请求与post提交区别的简易理解
正则系列之断言Assertions