我正在尝试加载在同步映射中任意定义的结构类型数据。是否有任何便捷的方法可以通过定义(如泛型、sync.Map[struct]{})来访问地图类型?package mainimport ( "sync")type mystruct struct { cnt int}func (m *mystruct) Add() { m.cnt++}func main() { m := sync.Map{} m.Store("a", &mystruct{1}) m.Store("b", &mystruct{1}) v, _ := m.Load("a") v.Add() // i know v.(*mystruct).Add() will solve problem. but is that really only solution?}https://go.dev/play/p/vme7Zuw-raB
- 1 回答
- 0 关注
- 54 浏览
添加回答
举报
0/150
提交
取消