when you assign a variable of pointer type to a new variable, just pass an address, two variables actually point to the same object, change one, that is, change both.
package main
import (
"container/list"
"fmt"
)
func main() {
l1 := list.New() // *list.List
l1.PushBack(1)
fmt.Println(l1.Back().Value) // 1
l2 := l1
l2.PushBack(2)
fmt.Println(l1.Back().Value, l2.Back().Value) // 2 2
l1.PushBack(3)
fmt.Println(l1.Back().Value, l2.Back().Value) // 3 3
}
is there any simple way to make a pointer type assignment like a value type assignment, make a copy of the value and pass it back?