golang slice append 总结

golang slice append 总结

var r *reward
var rs []*reward                        // [] 0 0
rs = append(rs, nil...)                 // [] 0 0
rs = append(rs, nil)                    // [<nil>] 1 1
rs = append(rs, r)                      // [<nil> <nil>] 2 2
rs = append(rs, []*reward{nil}...)      // [<nil> <nil> <nil>] 3 4
rs = append(rs, []*reward{nil}[:]...)   // [<nil> <nil> <nil> <nil>] 4 4
rs = append(rs, []*reward{r}...)        // [<nil> <nil> <nil> <nil> <nil>] 5 8
rs = append(rs, []*reward{}...)         // [<nil> <nil> <nil> <nil> <nil>] 5 8
rs = append(rs, &reward{})              // [<nil> <nil> <nil> <nil> <nil> 0x5a0020] 6 8
rs = append(rs, (*reward)(nil))         // [<nil> <nil> <nil> <nil> <nil> 0x5a0020 <nil>] 7 8
rs = append(rs, ([]*reward)(nil)...)    // [<nil> <nil> <nil> <nil> <nil> 0x5a0020 <nil>] 7 8
rs = append(rs, ([]*reward)(nil)[:]...) // [<nil> <nil> <nil> <nil> <nil> 0x5a0020 <nil>] 7 8

hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » golang slice append 总结