I have tried out the following code:
package main
import (
"fmt"
"sync"
)
type T string
func main() {
var a sync.Map // map[interface{}]interface{}
var c T
// a.Store("a", T("A"))
a.Store("a", "A")
b, _ := a.Load("a")
c = b.(T)
fmt.Println(c)
}
This gets an error of panic: interface conversion: interface {} is string, not main.T
.
However, it works if I use the commented line.
Aren't T
and string
of same underlying types? What's behind this?