gpt4 book ai didi

go - 在 goLang 中,谁来理解 *var.Type

转载 作者:数据小太阳 更新时间:2023-10-29 03:32:09 24 4
gpt4 key购买 nike

 11 func Map(value string) *list.List {
12 }

如上。“list”是var名,List是goLang内置类型。我如何理解 *list.List ?

它是一个带名称列表的列表指针吗?

另外,如果我的理解是正确的,这个列表中元素的类型是什么?它没有定义。

谢谢,

最佳答案

The Go Programming Language Specification

Function types

A function type denotes the set of all functions with the same parameter and result types. The value of an uninitialized variable of function type is nil.

FunctionType   = "func" Signature .
Signature = Parameters [ Result ] .
Result = Parameters | Type .
Parameters = "(" [ ParameterList [ "," ] ] ")" .
ParameterList = ParameterDecl { "," ParameterDecl } .
ParameterDecl = [ IdentifierList ] [ "..." ] Type .

Within a list of parameters or results, the names (IdentifierList) must either all be present or all be absent. If present, each name stands for one item (parameter or result) of the specified type and all non-blank names in the signature must be unique. If absent, each type stands for one item of that type. Parameter and result lists are always parenthesized except that if there is exactly one unnamed result it may be written as an unparenthesized type.


Package list

import "container/list"

Package list implements a doubly linked list.

type Element

type Element struct {

// The value stored with this element.
Value interface{}
// contains filtered or unexported fields
}

Element is an element of a linked list.

type List

type List struct {
// contains filtered or unexported fields
}

List represents a doubly linked list. The zero value for List is an empty list ready to use.


list 是一个包名。结果类型 *list.List 是指向类型 list.List 的指针。 list.List 类型的元素属于 list.Element 类型。例如,

package main

import "container/list"

func Map(value string) *list.List { return nil }

func main() {}

关于go - 在 goLang 中,谁来理解 *var.Type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23680431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com