当前位置:网站首页>Go language learning notes - language interface | go language from scratch
Go language learning notes - language interface | go language from scratch
2022-04-23 09:18:00 【Swordsman a Liang_ ALiang】
Learning notes , Where is where .
Go Language interface and Java The interface of is a little similar , The writing is not very consistent . Personally, I feel more like Java Defining abstract methods in a parent class is similar to , Any integration parent class needs to re implement the abstract method .
The sample code is as follows
package main
import "fmt"
type Phone interface {
call(param int) string
info()
}
type IPhone struct {
name string
number string
}
func (iphone IPhone) call(param int) string {
return fmt.Sprintf("%d,%s", param, iphone.name)
}
func (iphone IPhone) info() {
fmt.Printf(" My mobile information is :name=%s,number=%s\n", iphone.name, iphone.number)
}
func main() {
var phone Phone = IPhone{"haha", "1234"}
phone.info()
phone.call(12311111)
}
Execution results
My mobile information is :name=haha,number=1234
Be careful
1、 The interface is implemented in func The preceding parentheses specify the structure type parameter .
2、 The above sample code first defines Phone There are two ways to interface call、info,IPhone Structure implements two methods .
版权声明
本文为[Swordsman a Liang_ ALiang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230633437767.html
边栏推荐
- Node installation
- Common errors of VMware building es8
- SQL used query statements
- The K neighbors of each sample are obtained by packet switching
- Applet error: should have URL attribute when using navigateto, redirectto or switchtab
- First principle mind map
- Matlab draw five-star red flag
- Kettle experiment conversion case
- 2D 01 Backpack
- 3、 6 [Verilog HDL] gate level modeling of basic knowledge
猜你喜欢

108. 将有序数组转换为二叉搜索树

nn. Explanation of module class
![[58] length of the last word [leetcode]](/img/c5/3ba1fe5a81593d9576bb597f0d5f45.png)
[58] length of the last word [leetcode]

《数字电子技术基础》3.1 门电路概述、3.2 半导体二极管门电路

npm ERR! network

The crawler returns null when parsing with XPath. The reason why the crawler cannot get the corresponding element and the solution

【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)

Installation of data cleaning ETL tool kettle

数据清洗 ETL 工具Kettle的安装

Redis Desktop Manager for Mac
随机推荐
STM32 and FreeRTOS stack parsing
Introduction to matlab
《信息系统项目管理师总结》第八章 项目干系人管理
108. 将有序数组转换为二叉搜索树
NPM installation yarn
108. Convert an ordered array into a binary search tree
Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
kettle实验
Employee probation application (Luzhou Laojiao)
MySQL small exercise (only suitable for beginners, non beginners are not allowed to enter)
Go language self-study series | golang structure as function parameter
[SQL Server fast track] view and cursor of database
What is monitoring intelligent playback and how to use intelligent playback to query video recording
【原创】使用System.Text.Json对Json字符串进行格式化
Emuelec compilation summary
501. Mode in binary search tree
Applet in wechat and app get current ()
Production practice elk
Go language self-study series | golang nested structure
三、6【Verilog HDL】基础知识之门级建模