鉴于下面的示例,幕后实际发生了什么?
package main
import "fmt"
func main() {
s := "Hello"
t := s // t shares the same data as s
s += "World" // a new string is created
t += "There" // a new string is created.
fmt.Printf("%s %s\n", s, t)
}
输出:
HelloWorld HelloThere
问题是golang什么时候会判断需要创建新的副本呢?
慕无忌1623718
喵喵时光机
相关分类