在Golang中,未导出的标识符是包内部的公共标识符吗?

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

Are unexported identifier package public in Golang?

问题

正如主题所说,Golang中的未导出标识符package public吗?我阅读了规范,但没有找到相关内容。编译器似乎将未导出的函数名称视为文件私有而不是包公共。

英文:

As the subject says, are unexported identifiers package public in Golang?
I read the spec but can't find anything. The compiler seems to treat unexported function names as file private (and not package public).

答案1

得分: 1

所有顶级常量、类型、变量和函数都具有包范围。这包括这些种类的未导出标识符。具体的规范语言如下所示:

在顶级(任何函数之外)声明的常量、类型、变量或函数(但不包括方法)所表示的标识符的作用域是包块。

导入的包名是唯一具有文件范围的实体。

英文:

All top level constants, types variables and functions have package scope. This includes unexported identifiers of these kinds. The exact language from the specification is:

> The scope of an identifier denoting a constant, type, variable, or
> function (but not method) declared at top level (outside any function)
> is the package block.

Imported package names are the only entity with file scope.

huangapple
  • 本文由 发表于 2016年1月20日 10:26:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/34890480.html
匿名

发表评论

匿名网友

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

确定