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

边栏推荐
- squid代理服務器
- Codeforces Round #722 (Div. 2)
- OpenSSL 编程 二:搭建 CA
- Codeforces Round #721 (Div. 2)
- Experiment of love number lesson | phase V - emotion judgment of commodity review based on machine learning method
- SQL必需掌握的100个重要知识点:过滤数据
- Galaxy Kirin system LAN file sharing tutorial
- Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)
- Go从入门到实战——错误机制(笔记)
- DO280OpenShift访问控制--security policy和章节实验
猜你喜欢

ICML2022 | 可扩展深度高斯马尔可夫随机场

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!"

白嫖红队goby&POC,叫你如何白嫖?

AI 绘画极简教程

Go从入门到实战——任务的取消(笔记)

squid代理服務器

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

KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"

Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer

Go从入门到实战——Context与任务取消(笔记)
随机推荐
跟我一起AQS SOS AQS
squid代理服務器
MySQL usage notes 1
Codeforces Round #721 (Div. 2)
OpenSSL 编程 一:基本概念
Share how I take notes
A set of system to reduce 10 times the traffic pressure in crowded areas
Go from introduction to actual combat - context and task cancellation (notes)
麒麟V10安装字体
请教CMS小程序首页的幻灯片在哪里设置?
集合代码练习
Experience Navicat premium 16, unlimited reset, 14 day trial method (with source code)
图解基于AQS队列实现的CountDownLatch和CyclicBarrier
Shell script controls the startup and shutdown of services - with detailed cases
SQL必需掌握的100个重要知识点:过滤数据
Day8 ---- 云资讯项目介绍与创建
Codeforces Round #717 (Div. 2)
AI 绘画极简教程
100 important knowledge points that SQL must master: combining where clauses
MySQL客户端工具推荐,一定想不到最好用巨然是它