mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-12-20 04:34:20 +08:00
ch12: fix code path
This commit is contained in:
@@ -22,9 +22,8 @@ e.args[0].value.y.value = "pi"
|
||||
|
||||
在可能的情況下,你應該避免在一個包中暴露和反射相關的接口。我們將定義一個未導出的display函數用於遞歸處理工作,導出的是Display函數,它隻是display函數簡單的包裝以接受interface{}類型的參數:
|
||||
|
||||
<u><i>gopl.io/ch12/display</i></u>
|
||||
```Go
|
||||
gopl.io/ch12/display
|
||||
|
||||
func Display(name string, x interface{}) {
|
||||
fmt.Printf("Display %s (%T):\n", name, x)
|
||||
display(name, reflect.ValueOf(x))
|
||||
@@ -224,5 +223,3 @@ c.Value = 42
|
||||
**練習 12.1:** 擴展Displayhans,以便它可以顯示包含以結構體或數組作爲map的key類型的值。
|
||||
|
||||
**練習 12.2:** 增強display函數的穩健性,通過記録邊界的步數來確保在超出一定限製前放棄遞歸。(在13.3節,我們會看到另一種探測數據結構是否存在環的技術。)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user