当前位置:网站首页>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é

边栏推荐
- Covering access to 2w+ traffic monitoring equipment, EMQ creates a new digital engine for all elements of traffic in Shenzhen
- Codeforces Round #719 (Div. 3)
- 100 important knowledge points that SQL must master: sorting and retrieving data
- GFS distributed file system
- MySQL客户端工具推荐,一定想不到最好用巨然是它
- 请教CMS小程序首页的幻灯片在哪里设置?
- Go从入门到实战——channel的关闭和广播(笔记)
- 送你12个常用函数公式,用过的都说好
- Go from entry to practice - multiple selection and timeout control (notes)
- 如何将队列里面的内容没秒钟执行一次优先级
猜你喜欢

After being forced to develop the app within 20 days, the group was laid off, and the technical director angrily criticized it: I wish "closure as soon as possible!"

数据平台调度升级改造 | 从Azkaban 平滑过度到Apache DolphinScheduler 的操作实践

Go从入门到实战——共享内存并发机制(笔记)

空指针异常

Codeforces Round #716 (Div. 2)

互联网 35~40 岁的一线研发人员,对于此岗位的核心竞争力是什么?

How to participate in openharmony code contribution

Save method of JPA stepping pit series

Go从入门到实战—— 多路选择和超时控制(笔记)

Release of global Unicorn list in 2021: the full list of 301 Unicorn enterprises in China is coming!
随机推荐
After being forced to develop the app within 20 days, the group was laid off, and the technical director angrily criticized it: I wish "closure as soon as possible!"
Go从入门到实战——协程机制(笔记)
Scrum和看板的区别
关于企业数字化的展望(38/100)
SQL必需掌握的100个重要知识点:IN 操作符
BTC and eth recapture the lost land! Leading the market recovery? Encryption will enter the "ice age"!
Go from introduction to actual combat - all tasks completed (notes)
MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)
Go从入门到实战——共享内存并发机制(笔记)
Shell script controls the startup and shutdown of services - with detailed cases
Codeforces Round #717 (Div. 2)
使用storcli工具配置RAID,收藏这一篇就够了
Love math experiment | phase 9 - intelligent health diagnosis using machine learning method
Modify large online games through CE modifier
GFS distributed file system
String类的常用方法
01-Golang-环境搭建
squid代理服务器
数据平台调度升级改造 | 从Azkaban 平滑过度到Apache DolphinScheduler 的操作实践
跟我一起AQS SOS AQS