当前位置:网站首页>Go from starting to Real - Interface (note)
Go from starting to Real - Interface (note)
2022-06-27 21:37:00 【Accumulation ytu】
JavaInterface

GoInterface

type Mover interface {
move()
}
type dog struct {
}
func (d dog) move() {
fmt.Println("Les chiens bougent.")
}
func main() {
var x Mover
var wangcai = dog{
} // Wangcai estdogType
x = wangcai // xPeut recevoirdogType
var fugui = &dog{
} // La richesse est*dogType
x = fugui // xPeut recevoir*dogType
x.move()
}
D'après le code ci - dessus,Après avoir implémenté l'interface en utilisant le récepteur de valeur,Peu importe.dog Structure ou pointeur de structure *dog Toutes les variables de type peuvent être assignées à cette variable d'interface .Parce queGoIl y a du sucre syntaxique dans la langue qui évalue les variables de type pointeur,dogPointeur fugui L'intérieur évalue automatiquement *fugui
func (d *dog) move() {
fmt.Println("Les chiens bougent.")
}
func main() {
var x Mover
var wangcai = dog{
} // Wangcai estdogType
x = wangcai // xImpossible de recevoirdogType
var fugui = &dog{
} // La richesse est*dogType
x = fugui // xPeut recevoir*dogType
}
À ce stadeMoverL'interface est*dogType, Donc je ne peux pas donner xEntréedogTypewangcai,En ce momentxStockage seulement*dogValeur du type.
Variables d'interface

Type personnalisé

边栏推荐
- SQL Server for循环用法
- SQL必需掌握的100个重要知识点:组合 WHERE 子句
- MySQL performance optimization index function, hidden, prefix, hash index usage (2)
- 农产品期货怎么做怎么开户,期货开户手续费多少,找谁能优惠手续费?
- 释放开源数据库创新力量 | 【甘肃】openGauss Meetup圆满结束
- SQL必需掌握的100个重要知识点:创建计算字段
- Let Ma Huateng down! Web3.0, hopeless
- 数组作业题
- 猜拳游戏专题训练
- MySQL客户端工具推荐,一定想不到最好用巨然是它
猜你喜欢

Focus! Tips for installing fonts on domestic computers

MySQL usage notes 1

Industry case | see the operation of bank digital transformation from the king of retail

Modify large online games through CE modifier

01-Golang-环境搭建

Go从入门到实战——package(笔记)

让马化腾失望了!Web3.0,毫无希望

非常全面的DolphinScheduler(海豚调度)安装使用文档

GFS分布式文件系统

Go从入门到实战——接口(笔记)
随机推荐
100 important knowledge points that SQL must master: combining where clauses
Go from introduction to actual combat - context and task cancellation (notes)
Serveur mandataire SQUID
MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)
富文本 考试 填空题
Modify large online games through CE modifier
Go from entry to practice - multiple selection and timeout control (notes)
Let Ma Huateng down! Web3.0, hopeless
Very comprehensive dolphin scheduler installation and use documents
Go from introduction to actual combat - panic and recover (notes)
Codeforces Round #716 (Div. 2)
TreeSet详解
Goldfish rhca memoirs: do447 managing projects and carrying out operations -- creating job templates and starting jobs
2021全球独角兽榜发布:中国301家独角兽企业全名单来了!
SQL必需掌握的100个重要知识点:IN 操作符
今晚战码先锋润和赛道第2期直播丨如何参与OpenHarmony代码贡献
Wechat applet based service management system for college party members' Home System applet graduation design, Party members, activists, learning, punch in, forum
Go from introduction to actual combat - all tasks completed (notes)
Flask----应用案例
Codeforces Global Round 14