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

@@ -9,7 +9,7 @@
## 翻译进度 ## 翻译进度
11.7 [第一个例子使用Sorter接口排序](eBook/11.7.md) 11.9 [空接口](eBook/11.9.md)
## 支持本书 ## 支持本书

View File

@@ -28,4 +28,4 @@ Golang 编程245386165
|更新日期 |更新内容 |更新日期 |更新内容
|----------|------------------ |----------|------------------
|2015-09-12|11.7 第一个例子使用Sorter接口排序 |2015-09-13|11.9 空接口

2
TOC.md
View File

@@ -96,3 +96,5 @@
- 11.5 [测试一个值是否实现了某个接口](eBook/11.5.md) - 11.5 [测试一个值是否实现了某个接口](eBook/11.5.md)
- 11.6 [使用方法集与接口](eBook/11.6.md) - 11.6 [使用方法集与接口](eBook/11.6.md)
- 11.7 [第一个例子:使用 Sorter 接口排序](eBook/11.7.md) - 11.7 [第一个例子:使用 Sorter 接口排序](eBook/11.7.md)
- 11.8 [第二个例子:读和写](eBook/11.8.md)
- 11.9 [空接口](eBook/11.9.md)

0
eBook/11.10.md Normal file
View File

View File

@@ -2,7 +2,7 @@
读和写是软件中很普遍的行为提起它们会立即想到读写文件、缓存比如字节或字符串切片、标准输入输出、标准错误以及网络连接、管道等等或者读写我们的自定义类型。为了是代码尽可能通用Go 采取了一致的方式来读写数据。 读和写是软件中很普遍的行为提起它们会立即想到读写文件、缓存比如字节或字符串切片、标准输入输出、标准错误以及网络连接、管道等等或者读写我们的自定义类型。为了是代码尽可能通用Go 采取了一致的方式来读写数据。
`io` 包提供了用于读和写的接口`io.Reader``io.Writer` `io` 包提供了用于读和写的接口 `io.Reader``io.Writer`
```go ```go
type Reader interface { type Reader interface {

View File

@@ -154,9 +154,9 @@ var dataSlice []myType = FuncReturnSlice()
var interfaceSlice []interface{} = dataSlice 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` 语句来一个一个显式地复制: 必须使用 `for-range` 语句来一个一个显式地复制:
@@ -252,4 +252,4 @@ func f3(x myInterface) {
- [目录](directory.md) - [目录](directory.md)
- 上一节:[第二个例子:读和写](11.8.md) - 上一节:[第二个例子:读和写](11.8.md)
- 下一节:[反射](11.10.md) - 下一节:[对结构进行反射](11.10.md)