草庐IT

ByteSlice

全部标签

go - 为什么没有为命名指针类型定义方法?

在effectiveGo的文档中它指出:AswesawwithByteSize,methodscanbedefinedforanynamedtype(exceptapointer...typeByteSlice[]bytefunc(sliceByteSlice)Append(data[]byte)[]byte{//Bodyexactlythesameasabove}然后继续提供一个指针作为接收者的例子:func(p*ByteSlice)Append(data[]byte){slice:=*p//Bodyasabove,withoutthereturn.*p=slice}这不矛盾吗?或者

go - 为什么没有为命名指针类型定义方法?

在effectiveGo的文档中它指出:AswesawwithByteSize,methodscanbedefinedforanynamedtype(exceptapointer...typeByteSlice[]bytefunc(sliceByteSlice)Append(data[]byte)[]byte{//Bodyexactlythesameasabove}然后继续提供一个指针作为接收者的例子:func(p*ByteSlice)Append(data[]byte){slice:=*p//Bodyasabove,withoutthereturn.*p=slice}这不矛盾吗?或者