今天继续学习Go 1.18引入的泛型,我们将以Go官方的泛型教程为资料,每天利用几分钟的时间来学习,慢慢积累。 昨天我们定义了一个泛型函数,代码如下: 1// SumIntsOrFloats sums the values of map m. It supports both int64 and float64 2// as types for map values. 3func SumIntsOrFloats[K comparable, V int64 | float64](m map[K]V) V { 4 var s V 5 for _, v := range m { 6 s += v 7……