go语言接口简单范例
定义一个接口
type I interface{
Get() int
Put(int)
}
这段话就定义了一个接口,它包含两个函数Get和Put
 
好了,我的一个接口实现了这个接口:
type S stuct {val int}
func (this *S) Get int {
return this.val
}
func (this *S)Put(v int) {
this.val = v
}
go语言接口简单范例
定义一个接口
type I interface{
Get() int
Put(int)
}
这段话就定义了一个接口,它包含两个函数Get和Put
 
好了,我的一个接口实现了这个接口:
type S stuct {val int}
func (this *S) Get int {
return this.val
}
func (this *S)Put(v int) {
this.val = v
}