The function make is describe like this:
func make(Type, size IntegerType) Type
When we use make for slicing sometimes it shows like:
make([]int, 0, 10)
So my question is:
How can the make function take three parameters? The size IntegerType is not Vararg. I'm confused...
解决方案
The make function is one of a bunch of built-in functions that are allowed to do things that you cannot achieve (at least not cleanly and easily) in your Go code.
It has a number of overloaded forms for creating maps, channels and slices (see
https://golang.org/ref/spec#Making_slices_maps_and_channels) :
Your confusion probably stems from https://golang.org/pkg/builtin/#make which shows make as having the signature func make(Type, size IntegerType) Type.
If you look closer in that section, you would also see an indication that make can have a third argument:
Slice: The size specifies the length. The capacity of the slice is
equal to its length. A second integer argument may be provided to
specify a different capacity; it must be no smaller than the length,
so make([]int, 0, 10) allocates a slice of length 0 and capacity 10.
You can also notice that make can also be used without its integer argument:
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.
Channel: The channel's buffer is initialized with the specified buffer capacity. If zero, or the size is omitted, the channel is unbuffered.