Difference between make(map) and map{}

The Go Programming Language Specification

Making slices, maps and channels

The built-in function make takes a type T, which must be a slice, map
or channel type, optionally followed by a type-specific list of
expressions. It returns a value of type T (not *T). The memory is
initialized as described in the section on initial values.

Call         Type T  Result
make(T)      map     map of type T
make(T, n)   map     map of type T with initial space for approximately n elements

Composite literals

Composite literals construct values for structs, arrays, slices, and
maps and create a new value each time they are evaluated. They consist
of the type of the literal followed by a brace-bound list of elements.
Each element may optionally be preceded by a corresponding key.

map[string]int{}
map[string]int{"one": 1}

make is the canonical form. Composite literals are a convenient, alternate form.

z := make(map[int]string)

and

z := map[int]string{}

are equivalent.

Leave a Comment

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