mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-20 16:45:56 +08:00
23 lines
260 B
Go
23 lines
260 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func bad() {
|
|
src := []int{0, 1, 2}
|
|
var dst []int
|
|
copy(dst, src)
|
|
fmt.Println(dst)
|
|
|
|
_ = src
|
|
_ = dst
|
|
}
|
|
|
|
func correct() {
|
|
src := []int{0, 1, 2}
|
|
dst := make([]int, len(src))
|
|
copy(dst, src)
|
|
fmt.Println(dst)
|
|
|
|
_ = src
|
|
_ = dst
|
|
}
|