Why is 'list' lowercase when importing 'container/list' but 'List' is uppercase in Go?

DDD
Release: 2024-11-26 22:05:12
Original
512 people have browsed it

Why is

Public, Private - Upper Case, Lower Case

In Go, the public access modifier is achieved by declaring functions in upper case. However, this rule becomes confusing when interacting with container classes such as List.

The public members of imported packages are named in upper case. For instance, the List type in the "container/list" package is denoted as *list.List. However, the name of the package itself, which is "list" in this case, is written in lower case when imported.

This naming convention is used because you can alias imported packages as desired. By default, the package name is the last part of the package path. In the case of "container/list," the package name is "list," and it is imported using "import container/list."

Therefore, when declaring a local reference to a *list.List type, it is possible to use lower case, such as "l := list.New()." This is because "list" is the name of the imported package, not the type within that package.

The above is the detailed content of Why is 'list' lowercase when importing 'container/list' but 'List' is uppercase in Go?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template