Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Does Go support implicit conversion types?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report