Go newbie here. I am trying to assign an uint64 value to a variable of a named type with underlying type unit64. Compiler is unhappy and can't see the two types are exactly the same. What's the right way to do this?
package main
import "fmt"
import "math/rand"
type myType uint64
var x myType
func main() {
x = rand.Uint64()
fmt.Println(x)
}
This throws compiler error:
./prog.go:12:4: cannot use rand.Uint64() (type uint64) as type myType in assignment
You can convert it myType(rand.Uint64())
. Usefull links: Type Assertion in Go and Type Conversion in Go as well as an excellent answer in this stack overflow question "How to cast to a type alias in go"