11.8-11.9

This commit is contained in:
Unknwon
2015-09-13 21:37:43 -04:00
parent 778950f37c
commit c264763a66
7 changed files with 12 additions and 10 deletions

View File

@@ -2,7 +2,7 @@
## 11.9.1 概念
**空接口或者最小接口**不包含任何方法,它对实现不做任何要求:
**空接口或者最小接口** 不包含任何方法,它对实现不做任何要求:
```go
type Any interface {}
@@ -154,9 +154,9 @@ var dataSlice []myType = FuncReturnSlice()
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](http://golang.org/doc/go_spec.html))。
原因是它们俩在内存中的布局是不一样的(参考 [官方说明](http://golang.org/doc/go_spec.html))。
必须使用 `for-range` 语句来一个一个显式地复制:
@@ -252,4 +252,4 @@ func f3(x myInterface) {
- [目录](directory.md)
- 上一节:[第二个例子:读和写](11.8.md)
- 下一节:[反射](11.10.md)
- 下一节:[对结构进行反射](11.10.md)