mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:11:49 +08:00
Update 11.9.md (#654)
This commit is contained in:
@@ -156,7 +156,7 @@ var interfaceSlice []interface{} = dataSlice
|
|||||||
|
|
||||||
可惜不能这么做,编译时会出错:`cannot use dataSlice (type []myType) as type []interface { } in assignment`。
|
可惜不能这么做,编译时会出错:`cannot use dataSlice (type []myType) as type []interface { } in assignment`。
|
||||||
|
|
||||||
原因是它们俩在内存中的布局是不一样的(参考 [官方说明](http://golang.org/doc/go_spec.html))。
|
原因是它们俩在内存中的布局是不一样的(参考 [Go wiki](https://github.com/golang/go/wiki/InterfaceSlice))。
|
||||||
|
|
||||||
必须使用 `for-range` 语句来一个一个显式地复制:
|
必须使用 `for-range` 语句来一个一个显式地复制:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user