Skip to content

Commit 406741b

Browse files
committed
Explain correct situation too
1 parent 2cae554 commit 406741b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

content/chapter 6/6.7-limitations, errors, and anti-patterns in generics.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,23 @@ weight: 11007
5959
#### مثال واقعی خطا:
6060

6161
```go
62+
package main
63+
64+
import "fmt"
65+
6266
func PrintMapKeys[K comparable, V any](m map[K]V) {
63-
for k := range m {
64-
fmt.Println(k)
65-
}
67+
for k := range m {
68+
fmt.Println(k)
69+
}
6670
}
6771

68-
PrintMapKeys(map[[]int]int{}) // error: []int does not implement comparable
72+
func main() {
73+
PrintMapKeys(map[[]int]int{}) // error: []int does not implement comparable
74+
75+
// use this instead:
76+
// testMap := make(map[string]int)
77+
// PrintMapKeys(testMap)
78+
}
6979
```
7080

7181
---

0 commit comments

Comments
 (0)