go 疑难杂症

func Test_doSeond(t *testing.T) {
    msg := make([]Msg, 0)
    for i := 0; i < 5; i++ {
        m := Msg{
            data: []byte(strconv.Itoa(i)),
            addr: "wewe",
        }
        msg = append(msg, m)
    }

    m := make([]*Msg, 0)
    for _, v := range msg {
        m = append(m, &v)
    }
    for _, v := range m {
        fmt.Println(string(v.data))
    }
    time.Sleep(10 * time.Second)
}

自己跑下结果,会出人意料哦~~~

相关推荐