加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Golang 接收器是指针还是至类型的区别

发布时间:2020-12-16 18:56:54 所属栏目:大数据 来源:网络整理
导读:Go语言可以根据下面的函数: func(a Integer) Less(b Integer) bool 自动生成一个新的Less()方法: func(a *Integer) Less(b Integer) bool{ return(*a).Less(b) } 这样,类型*Integer就既存在Less()方法,也存在Add()方法,满足LessAdder接口。而 从另一方面
Go语言可以根据下面的函数:
func(a Integer) Less(b Integer) bool

自动生成一个新的Less()方法:
func(a *Integer) Less(b Integer) bool{
return(*a).Less(b)

}

这样,类型*Integer就既存在Less()方法,也存在Add()方法,满足LessAdder接口。而 从另一方面来说,根据 func(a *Integer) Add(b Integer) 这个函数无法自动生成以下这个成员方法: func(a Integer) Add(b Integer) { (&a).Add(b) }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读