Why doesn’t Golang allow const maps?

From https://golang.org/ref/spec#Constants:

A constant value is represented by a rune, integer, floating-point,
imaginary, or string literal, an identifier denoting a constant, a
constant expression, a conversion with a result that is a constant, or
the result value of some built-in functions such as unsafe.Sizeof
applied to any value, cap or len applied to some expressions, real and
imag applied to a complex constant and complex applied to numeric
constants.

tl;dr only numeric types, strings and bools can be constants, arrays, slices and maps aren’t a numeric type.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)