go的内建函数len为什么返回int而不是uint?

// The len built-in function returns the length of v, according to its type:
//
// Array: the number of elements in v.
// Pointer to array: the number of elements in *v (even if v is nil).
// Slice, or map: the number of elements in v; if v is nil, len(v) is zero.
// String: the number of bytes in v.
// Channel: the number of elements queued (unread) in the channel buffer;
// if v is nil, len(v) is zero.
//
// For some arguments, such as a string literal or a simple array expression, the
// result can be a constant. See the Go language specification's "Length and
// capacity" section for details.
func len(v Type) int

返回int是有什么其他的考量吗?

长度返回uint不是更合理吗?

作者:1原文地址:https://segmentfault.com/q/1010000043369161

%s 个评论

要回复文章请先登录注册