摘要: package main import ( "bytes" "fmt" "io" ) // 此处的w参数默认是一个空接口,当传递进来buf参数时,w就不是空接口了,因为它有类型了,但是动态值是一个空指针 nil func test(w io.Writer) { if w != nil { fmt.P 阅读全文
posted @ 2021-11-03 16:49 专职 阅读(90) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" ) type Sayer interface { say() } type Mover interface { move() } type Animal interface { // 接口与接口嵌套创造出新的接口,Animal接口有Sayer和 阅读全文
posted @ 2021-11-03 16:09 专职 阅读(334) 评论(0) 推荐(0) 编辑
摘要: 总结: 1. 值类型的嵌入式字段,该类型拥有值类型的方法集,没有值指针类型的方法集 2. 指针类型的嵌入式字段,该类型拥有值指针类型的方法集,没有值类型的方法集,并且,该类型的指针类型也有值指针类型的方法集 有点绕,见案例: package main import "fmt" type Boss s 阅读全文
posted @ 2021-11-03 13:41 专职 阅读(256) 评论(0) 推荐(0) 编辑