码迷,mamicode.com
首页 > 其他好文 > 详细

golang 自定义接口 和 实现接口

时间:2020-02-16 16:39:44      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:value   cte   object   byte   type   lan   imp   int   pre   

 1 /*
 2     定义:
 3     type 接口名 interface{
 4         方法名(可选:参数列表) 可选:返回值列表 || (可选:返回值列表)
 5     }
 6     例:type Writer interface {
 7         Write(p []byte) (n int, err error)
 8     }
 9     type Objecter interface{//定义接口
10         say(class int, value string) (b bool, err error)
11     }
12     实现接口:
13         1:接口的方法与实现接口的类型方法格式一致
14         2:当一个接口中有多个方法时,只有这些方法都被实现了,接口才能被正确编译并使用
15 */
16 
17 package info_interface
18 
19 import "fmt"
20 
21 func Say(){
22     fmt.Println("info_interface")
23 }

 

golang 自定义接口 和 实现接口

标签:value   cte   object   byte   type   lan   imp   int   pre   

原文地址:https://www.cnblogs.com/weihexinCode/p/12317064.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!