jinzhu / copier

Copier for golang, copy value from struct to struct and more
MIT License
5.57k stars 489 forks source link

Slice replication problem #176

Open w22296437978 opened 1 year ago

w22296437978 commented 1 year ago

type Dto struct {
    Name string
}

func main() {
    list1 := []Dto{{"你好"}}
    list2 := []Dto{}

    copier.Copy(&list2, &list1)
    fmt.Printf("list2 length = %d\r\n", len(list2)) // 1

    list2 = []Dto{}
    list1Interface := method(list1)
    copier.Copy(&list2, &list1Interface)
    fmt.Printf("list2 length = %d\n", len(list2)) // 0 ???

    list2 = []Dto{}
    list1Interface = method(list1)
    copier.Copy(&list2, list1Interface)
    fmt.Printf("list2 length = %d\n", len(list2)) // 1 ???
}

func method(a interface{}) interface{} {
    return a
}