Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Does Go support implicit conversion types?

Shulou Source: shulou.com Published: 2022-05-31 13:49:26 10月28日 Update

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.

Tags: Type support knowledge content article value easy to operate article easy to understand more read it industry information channel channel will report learn Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info Microsoft MariaDB macOS