I was looking at the Slice Tricks: https://github.com/golang/go/wiki/SliceTricks
and I noticed in their copy example they have []T(nil)
I haven't seen (nil)
like this before and I can't find any documentation on using it or what exactly it accomplishes (I know it's self explanatory but I want to know how it acts the same as make
or []string{}
the only reference I can find by googling "golang (nil) slice" is
Since the zero value of a slice (nil) acts like a zero-length slice, you can declare a slice variable and then append to it in a loop:
But it doesn't say where it can be used or exactly what it accomplishes, like can I use this with structs or whatever I want?
e.g.:
package main
import "log"
func main() {
str := []string{"Hello", "Bye", "Good Day", "????????"}
cop := append([]string(nil), str...)
log.Println(str)
log.Println(cop)
}
I'm strictly only curious about how (nil)
operates, and what it can operate on.
Like does
[]string(nil)
Operate the same as
[]string{}
or what is the difference here