Type conversion
In general, Go considers each type to be different. This means under normal circumstances, values of different types are not fungible in assignment, function parameters, and expression contexts. This is true for built-in and declared types. For instance, the following will cause a build error due to type mismatch:
package main import "fmt" type signal int func main() { var count int32 var actual int var test int64 = actual + count var sig signal var event int = sig fmt.Println(test) fmt.Println(event) }
golang.fyi/ch04/type_conv.go
The expression actual + count
causes a build time error because both variables are of different types. Even though variables actual
and count
are of numeric types and int32
and int
have the same memory ...
Get Learning Go Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.