2 ms·
They can't for a very good reason. Let's say library A decides to add func (i int) MyMethod() and library B decides to add func (i int) MyMethod(). Then libra
by kjksf 10y ago
They can't for a very good reason.
Let's say library A decides to add func (i int) MyMethod() and library B decides to add func (i int) MyMethod().
Then library C calls i.MyMethod(). Which MyMethod is executed?
You can come up with an answer to that question (e.g. "pick random") but there is no sensible answer.
To avoid this ambiguity you can only add methods to your own types but not someone else's (i.e. not to types defined in other packages or basic types).