doushi6932 2018-09-18 23:54
浏览 136
已采纳

go中的函数数组语法是什么意思?

var list = []func(*someType) error {
        ...
    }

I am new to Go and I am trying to understand what does the syntax mean ? Is the return of function an array?

  • 写回答

2条回答 默认 最新

  • dtamho6404 2018-09-19 00:03
    关注

    This declares and initializes a variable list as a slice whose elements are functions with signature func(*someType) error.

    Slices in Go are convenient mechanisms for representing sequences of data of a particular type. They have type []T for any element type T (but remember Go does not have generics). A slice is defined only by the type of the items it contains; its length is not part of its type definition and can change at runtime. (Arrays in Go, by contrast, are of fixed length - their type is [N]T for length N and element type T).

    Under the surface, a slice consists of a backing array, a length of the current data and a capacity. The runtime manages the memory allocation of the array to accommodate all data in the slice.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 labview程序设计
  • ¥15 为什么nacos注册失败了呀?
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 游戏盾如何溯源服务器真实ip?
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。
  • ¥50 win10链接MySQL