英文:
What does type ByKey []mr.KeyValue{} mean?
问题
我完全不了解Go语言,也不知道不同的语言特性何时会一起出现。type ByKey []mr.KeyValue{}
,有人可以解释一下这是什么意思吗?
英文:
I am completely new in Go and have no idea when different language features bump up together,
type ByKey []mr.KeyValue{}
could any one please explain what this means?
答案1
得分: 0
如您在golang.org/ref/spec#Types中所见:
类型确定了一组值以及与这些值相关的操作和方法。如果一个类型有名称,可以用类型名称来表示它,否则可以使用类型字面量来指定它,类型字面量由现有类型组成。
类型定义
类型定义创建了一个新的、独立的类型,具有与给定类型相同的基础类型和操作,并将标识符绑定到它上面。
type ByKey []mr.KeyValue
是一个类型定义。它创建了一个名为 ByKey
的新类型,其基础类型是 []mr.KeyValue
。KeyValue
是在不同的包中定义的导出类型,作为 mr
导入到当前文件中,该文件包含了 type ByKey []mr.KeyValue
。
英文:
As you can see in golang.org/ref/spec#Types
> A type determines a set of values together with operations and methods
> specific to those values. A type may be denoted by a type name, if it
> has one, or specified using a type literal, which composes a type from
> existing types.
And in Type_declarations
> Type definitions
>
> A type definition creates a new, distinct type with
> the same underlying type and operations as the given type, and binds
> an identifier to it.
type ByKey []mr.KeyValue
is a type definition. It creates a new type called ByKey
with underlying type of []mr.KeyValue
. KeyValue
is again defined exported type in a different package imported as mr
to current file which included type ByKey []mr.KeyValue
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论