在Golang中,我应该将哪种类型用于仅方法类型?

wen*_*ner 1 oop go

我的意思是像这样的方法类型

var Util util
type util struct { }
func (util)Help(v VM) {}
func (util)HelpMe(v VM) {}
func (util)HelpYou(v VM) {}
func (util)HelpEveryOne(v VM) {}
Run Code Online (Sandbox Code Playgroud)

我在二进制文件中看到了这一点.BigEndian

// LittleEndian is the little-endian implementation of ByteOrder.
var LittleEndian littleEndian

// BigEndian is the big-endian implementation of ByteOrder.
var BigEndian bigEndian

type littleEndian struct{}
Run Code Online (Sandbox Code Playgroud)

这是对方法进行分组的一种非常棘手的方法.所以问题是:为什么struct{}?为什么不只是一个int别名,有没有理由选择struct{}其他类型?

joc*_*hen 5

我认为struct {}和之间的主要区别int是不struct {}占用内存,而未使用int会浪费4或8个字节.