mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 22:00:03 +08:00
11.8-11.9
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
## 翻译进度
|
||||
|
||||
11.7 [第一个例子:使用Sorter接口排序](eBook/11.7.md)
|
||||
11.9 [空接口](eBook/11.9.md)
|
||||
|
||||
## 支持本书
|
||||
|
||||
|
@@ -28,4 +28,4 @@ Golang 编程:245386165
|
||||
|
||||
|更新日期 |更新内容
|
||||
|----------|------------------
|
||||
|2015-09-12|11.7 第一个例子:使用Sorter接口排序
|
||||
|2015-09-13|11.9 空接口
|
2
TOC.md
2
TOC.md
@@ -96,3 +96,5 @@
|
||||
- 11.5 [测试一个值是否实现了某个接口](eBook/11.5.md)
|
||||
- 11.6 [使用方法集与接口](eBook/11.6.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
0
eBook/11.10.md
Normal file
@@ -2,7 +2,7 @@
|
||||
|
||||
读和写是软件中很普遍的行为,提起它们会立即想到读写文件、缓存(比如字节或字符串切片)、标准输入输出、标准错误以及网络连接、管道等等,或者读写我们的自定义类型。为了是代码尽可能通用,Go 采取了一致的方式来读写数据。
|
||||
|
||||
`io` 包提供了用于读和写的接口:`io.Reader` 和 `io.Writer`
|
||||
`io` 包提供了用于读和写的接口 `io.Reader` 和 `io.Writer`:
|
||||
|
||||
```go
|
||||
type Reader 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)
|
Reference in New Issue
Block a user