Map Immutability
Explain why the code below cannot compile and fix it.
package main
type S struct {
name string
}
func main() {
m := map[string]S{"x": S{"one"}}
m["x"].name = "two"
}
Answer
package main
type S struct {
name string
}
func main() {
m := map[string]*S{"x": &S{"one"}}
m["x"].name = "two"
}