“type ByKey []mr.KeyValue{}” 的意思是什么?

huangapple go评论150阅读模式
英文:

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_declarations中:

类型定义

类型定义创建了一个新的、独立的类型,具有与给定类型相同的基础类型和操作,并将标识符绑定到它上面。

type ByKey []mr.KeyValue 是一个类型定义。它创建了一个名为 ByKey 的新类型,其基础类型是 []mr.KeyValueKeyValue 是在不同的包中定义的导出类型,作为 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.

huangapple
  • 本文由 发表于 2021年8月26日 06:49:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/68930663.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定