16 Star 64 Fork 50

ShirDon-廖显东/Go语言高级开发与实战-随书代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
1.7.3-interface1.go 972 Bytes
一键复制 编辑 原始数据 按行查看 历史
ShirDon-廖显东 提交于 2021-12-28 09:45 . commit
//++++++++++++++++++++++++++++++++++++++++
// 《Go语言高级开发与实战》源码
//++++++++++++++++++++++++++++++++++++++++
// Author:廖显东(ShirDon)
// Blog:https://www.shirdon.com/
// 知乎:https://www.zhihu.com/people/shirdonl
// 公众号:源码大数据
// 仓库地址:https://gitee.com/shirdonl/goAdvanced
// 仓库地址:https://github.com/shirdonl/goAdvanced
//++++++++++++++++++++++++++++++++++++++++
package main
import "fmt"
type InterfaceFile interface {
Read()
Write()
}
type InterfaceReader interface {
Read()
}
type File struct {
}
func (f *File) Read() {
}
func (f *File) Write() {
}
func main() {
f := new(File)
var f1 InterfaceFile = f
var f2 InterfaceReader = f1
var f3 InterfaceReader = new(File)
// 接口查询
if f5, ok := f3.(InterfaceFile); ok {
fmt.Println(f5)
}
// 询问接口它指向的对象是否是某个类型
if f6, ok := f3.(*File); ok {
fmt.Println(f6)
}
fmt.Println(f1, f2, f3)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shirdonl/goAdvanced.git
git@gitee.com:shirdonl/goAdvanced.git
shirdonl
goAdvanced
Go语言高级开发与实战-随书代码
0f051d9f4e35

搜索帮助

D67c1975 1850385 1daf7b77 1850385