可以在: https://go2goplay.golang.org/ 去尝试下go的泛型
官方表示有可能在go1.17版本中添加,最早时间可能是2021年8月份
大概代码如下:
package mainimport ( "fmt")func Print(type T)(s []T) { for _, v := range s { fmt.Print(v) }}func main() { Print([]string{"Hello, ", "playground\n"}) Print(int)([]int{1, 2, 3})}
更多查看:
https://github.com/golang/pro…
https://go.googlesource.com/p…
文章来源:智云一二三科技
文章标题:golang 泛型预览版发布
文章地址:https://www.zhihuclub.com/7167.shtml