We can make channel by make
function, new an object by {}
expression.
ch := make(chan interface{})
o := struct{}{}
But, what's difference between make
and {}
to new a map?
m0 := make(map[int]int)
m1 := map[int]int{}
We can make channel by make
function, new an object by {}
expression.
ch := make(chan interface{})
o := struct{}{}
But, what's difference between make
and {}
to new a map?
m0 := make(map[int]int)
m1 := map[int]int{}
From the docs for the make
keyword:
Map: An initial allocation is made according to the size but the resulting map has length 0. The size may be omitted, in which case a small starting size is allocated.
So, in the case of maps, there is no difference between using make
and using an empty map literal.