day9接口

master
独孤伶俜 2022-12-14 22:42:18 +08:00
parent 2e765820cd
commit 732a8889dc
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package main
import "fmt"
type www interface {
Write()
}
type ByteCounter int
func (c *ByteCounter) Write(p []byte) (int, error) {
*c += ByteCounter(len(p))
return len(p), nil
}
func main() {
var c ByteCounter
c.Write([]byte("hello"))
fmt.Println(c)
name := "dugulp"
fmt.Fprintf(&c, "Hello, %s", name)
fmt.Println(c)
}