Does Go support implicit conversion types?
This article mainly introduces Go support implicit conversion type related knowledge, content detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that everyone will read this Go support implicit conversion type article will have something to gain, let's take a look at it.
Go does not support implicit conversion types, such as:
package mainimport "fmt"func main() { var a int64 = 3 var b int32 b = a fmt.Printf("b is: %d", b) }
At this time, it will report an error
cannot use a (type int64) as type int32 in assignmentcannot use b (type int32) as type string in argument to fmt.Printf
But if you change it to b = int32(a), you won't get it wrong:
package mainimport "fmt"func main() { var a int64 = 3 var b int32 b = int32(a) fmt.Printf("b is: %d", b) } About "Does Go support implicit conversion types" The content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of the knowledge of "Does Go support implicit conversion types?" If you still want to learn more knowledge, please pay attention to the industry information channel.