mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:06:41 +08:00
mod: 11.9.md (#749)
This commit is contained in:
@@ -246,7 +246,7 @@ func f3(x myInterface) {
|
||||
}
|
||||
```
|
||||
|
||||
`x` 转换为 `myPrintInterface` 类型是完全动态的:只要 `x` 的底层类型(动态类型)定义了 `print` 方法这个调用就可以正常运行。
|
||||
`x` 转换为 `myPrintInterface` 类型是完全动态的:只要 `x` 的底层类型(动态类型)定义了 `print` 方法这个调用就可以正常运行(译注:若 `x` 的底层类型未定义 `print` 方法,此处类型断言会导致 `panic`,最佳实践应该为 `if mpi, ok := x.(myPrintInterface); ok { mpi.print() }`,参考 11.3 章节)。
|
||||
|
||||
## 链接
|
||||
|
||||
|
Reference in New Issue
Block a user