demo
package main
import "fmt"
type a interface {
show()
}
type p struct {
name string
}
func (p1 * p)show1() {
fmt.Println("show name : "+p1.name)
}
// 语法: var _ 目标接口 = new(判断结构体)
var _ a = new(p)
func main() {
}
如果未实现报错如下
# command-line-arguments
./main.go:17:5: cannot use new(p) (type *p) as type a in assignment:
*p does not implement a (missing show method)