day9接口
parent
2e765820cd
commit
732a8889dc
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue