mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
make?
parent
4a4abf8262
commit
b891cf35f0
@ -68,14 +68,14 @@ Slice elements are almost identical to variables. Because they are addressable,
|
||||
Map elements are not addressable. Therefore, the following is an _illegal_ operation:
|
||||
|
||||
```go
|
||||
lists := map[string]List
|
||||
lists := map[string]List{}
|
||||
lists["primes"].Append(7) // cannot be rewritten as (&lists["primes"]).Append(7)
|
||||
```
|
||||
|
||||
However, the following is still valid (and is the far more common case):
|
||||
|
||||
```go
|
||||
lists := map[string]*List
|
||||
lists := map[string]*List{}
|
||||
lists["primes"] = new(List)
|
||||
lists["primes"].Append(7)
|
||||
count := lists["primes"].Len() // can be rewritten as (*lists["primes"]).Len()
|
||||
|
Loading…
x
Reference in New Issue
Block a user