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!