Go的同步。无法添加映射加载结果

Go的同步。无法添加映射加载结果,go,Go,我只是想做一些简单的创建或添加sync.Map gore> :import sync gore> var sm sync.Map gore> sm.Store(12345,1) gore> result, ok := sm.Load(12345) 1 true gore> newr := result +1 # command-line-arguments /var/folders/kl/n95_c8j15wn1784jmsq08mq80000gn/T/112740

我只是想做一些简单的创建或添加sync.Map

gore> :import sync
gore> var sm sync.Map
gore> sm.Store(12345,1)
gore> result, ok := sm.Load(12345)
1
true
gore> newr := result +1
# command-line-arguments
/var/folders/kl/n95_c8j15wn1784jmsq08mq80000gn/T/112740772/gore_session.go:21:17: invalid operation: result + 1 (mismatched types interface {} and int)
error: exit status 2
exit status 2
repl上的结果为1,但无法将其与1相加

对于接口类型为x的表达式和类型为T的表达式,主 表情

x.(T)
断言x不是nil,并且存储在x中的值是T类型。 表示法x.T称为类型断言

错误消息告诉所有人:

invalid operation: result + 1 (mismatched types interface {} and int)
在int的结果类型接口{}上使用类型断言:

游乐场:

输出:

1 true
2
1 true
2