当前位置:网站首页>Go language self-study series | golang type definition and type alias
Go language self-study series | golang type definition and type alias
2022-04-21 22:52:00 【COCOgsta】
Video source :B standing 《golang Introduction to project practice [2021 newest Go Language course , There is no nonsense , Dry only ! Ongoing update ...]》
Organize the teacher's course content and test notes while studying , And share it with you , Infringement is deleted , Thank you for your support !
Attach summary sticker :Go Language self-study series | Summary _COCOgsta The blog of -CSDN Blog
Before introducing the structure , Let's first look at what type definitions and type aliases are .
go Language type definition
Syntax of type definition
type NewType Type
example
package main
import "fmt"
func main() {
// The type definition
type MyInt int
// i by MyInt type
var i MyInt
i = 100
fmt.Printf("i: %v i: %T\n", i, i)
}
Running results
[Running] go run "/Users/guoliang/SynologyDrive/ software development /go/golang Introduction to project practice /goproject/360duote.com/pro01/test.go"
i: 100 i: main.MyInt
go Language type alias
Syntax of type aliases
type NewType = Type
example
package main
import "fmt"
func main() {
// Type alias definition
type MyInt2 = int
// i In fact, or int type
var i MyInt2
i = 100
fmt.Printf("i: %v i: %T\n", i, i)
}
go The difference between language type definition and type alias
- Type definition is equivalent to defining a new type , Different from the previous type ; But the type alias does not define a new type , Instead, use an alias to replace the previous type
- Type aliases will only exist in code , The alias does not exist after compilation
- Because the type alias is consistent with the original type , So the methods owned by the original type , You can also call... In the type alias , But if it's a redefined type , Then you can't call any of the previous methods
版权声明
本文为[COCOgsta]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212034375917.html
边栏推荐
- Exercise questions and answers of basic theories and relevant laws and regulations in 2022 supervision engineer examination
- Intelligent Cloud business group (ACG)
- 传统企业数字化商业探讨-数字化架构设计(5)
- Sorting methods (8 kinds) detailed explanation 6 - quick sorting
- Wiki. JS configure LDAP authentication
- Review questions and answers of building materials and structures in 2022 first-class registered architect examination
- Kubenetes (3) -- network communication (2) -- flannel and calico
- 深入理解mysql各种锁
- Redis advanced: data deletion and elimination strategy, master-slave replication, sentinel mode, cluster, enterprise solution
- 2022電視盒子加購榜排名,超一多半的用戶選購當貝盒子
猜你喜欢

Some cold thoughts behind the popularity of microservices, middle office, RPA and low code

After learning the linked list, don't you find some classic examples to consolidate your knowledge? The five OJ classic examples of the linked list, can you? Let's have a look (knowledge analysis + gr

1956年高考数学

MySQL read / write separation

Analysts believe that Samsung Galaxy Z fold 4 and Z flip 4 may be cheaper than their previous products

We sincerely invite you to sign up for the first openharmony developer growth plan sharing day

Kubenetes (3) -- network communication (2) -- flannel and calico

Ros2 robot modeling URDF 8.1 URDF unified robot modeling language

Kubernetes---Secret配置管理

MySQL multi table query exercise
随机推荐
GO111MODULE=on go mod init错误(go: cannot determine module path for source directory)
Reproduce the pathways language model using colossal AI
MySQL read / write separation
Intelligent Cloud business group (ACG)
[Résumé de quelques conseils et raccourcis clavier dans MATLAB]
What is the core design of Dadi's performance advantage in the cache hit scenario?
2022 TV box plus purchase list ranking, more than half of users buy dangbei box
[Central South University of forestry science and technology] [Chen] ninth week operation triangle exception handling
循环队列与扩容
Image processing in opencv -- an example of discrete Fourier transform (11)
Opencv -- geometric transformation
自建vnc类软件注意事项
[matlab] matlab drawing operation skills
Outsourcing student management system detailed architecture design document
REM practical development adaptation scheme for mobile web development
查询哪些表有唯一索引(除了主键)
Nacos Registry - service registration and tiered storage
Review questions and answers of building materials and structures in 2022 first-class registered architect examination
PyQt5+OpenCV操作本地摄像头
L1-062 lucky lottery (15 points)