Specify for the K
type parameter the type constraint comparable
.
Intended specifically for cases like these, the comparable
constraint
is predeclared in Go. It allows any type whose values may be used as an
operand of the comparison operators ==
and !=
. Go requires that map
keys be comparable.
If you want to change selection, open document below and click on "Move attachment"
Tutorial: Getting started with generics - The Go Programming LanguagemIntsOrFloats function with two type parameters (inside the square brackets), K and V, and one argument that uses the type parameters, m of type map[K]V. The function returns a value of type V. <span>Specify for the K type parameter the type constraint comparable. Intended specifically for cases like these, the comparable constraint is predeclared in Go. It allows any type whose values may be used as an operand of the comparison operators == and !=. Go requires that map keys be comparable. So declaring K as comparable is necessary so you can use K as the key in the map variable. It also ensures that calling code uses an allowable type for map keys. Specify for the V type Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details