【Golang 中的 type A = XXX 与 type A XXXX的区别】
Golang 中的 type A = XXX 与 type A XXXX的区别
- 先上代码
- 运行结果
- 结论
先上代码
package mainimport ("fmt"
)
type A = map[string]string
type B map[string]string
func main() {a := A{"a": "1", "b": "2"}b := B{"a": "1", "b": "2"}fmt.Printf("A type is %T\n", a)fmt.Printf("B type is %T\n", b)}
运行结果
A type is map[string]string
B type is main.B
结论
type A = map[string]string
这种是在给 map[string]string
取一个别名叫 A
type B map[string]string
这种是在给 定义一个新的类型为 B
基础类型是 map[string]string
。
虽然这两种方式定义的目的都 一样,但本质上是不一样的 。
【Golang 中的 type A = XXX 与 type A XXXX的区别】相关推荐
- golang中 type func() 用法分析
在看golang 的http服务部分代码时,被golang 中的 type func()写法难住了,一时没看懂代码.后来查资料后,有了一点理解. 在golang中可以通过这样简单实现一个http服务 ...
- golang 错误: cannot use XXX literal (type XXX) as type XXX in assignment:XXX does not implement XXX
出错代码如下: package mainimport ("fmt" )type Speaker interface {Hello() }type User struct {Name ...
- Golang反射机制的实现分析——reflect.Type方法查找和调用
在<Golang反射机制的实现分析--reflect.Type类型名称>一文中,我们分析了Golang获取类型基本信息的流程.本文将基于上述知识和经验,分析方法的查找和调用.(转载请指明出 ...
- tomcat 报错 Status 500 - Mapper method ‘xxxxx‘ has an unsupported return type: class xxx
myBatis 接口写了 insert ,对应的dao层里写的返回值是一个实体类 User add(User user); 报错 Status 500 - Mapper method 'xxxxx' ...
- Error while extracting response for type [class xxx] and content type application/xml;charset=UTF-8
强烈推荐一个大神的人工智能的教程:http://www.captainbed.net/zhanghan [前言] 最近在用restTemplate进行一次http请求时发现了报错(Error whil ...
- Unable to determine the relationship represented by navigation ‘XXX‘ of type ‘XXX‘.
项目场景: ABP项目执行数据库迁移 问题描述: Unable to determine the relationship represented by navigation 'XXX' of typ ...
- Type com.xxx.xxx.BuildConfig is defined multiple times:...
版权声明:本文为延成原创文章,转载请标明出处 问题复现 >Type com.xxx.xxx.BuildConfig is defined multiple times:- 编译的时候发生. 问题 ...
- 引用feignClient对象项目启动异常-Consider defining a bean of type ‘com.xxx.service.xxxRemote‘ in your configura
项目中依赖其他项目提供的feign接口,服务无法启动.控制台打印相关信息. Field channelApiInfoRemote in com.xxx.xxx.service.impl.xxxImpl ...
- xcode no rule to process file xxx of type解决
在Xcode编译的时候,黄色警告提示:[WARN]warning:no rule to process file 'XXX' of type sourcecode.c.h for architectu ...
最新文章
- 30万奖金!首个有阿里技术培训支持,让AI落定场景应用的赛事!
- 在 Ubuntu Linux 上从源代码构建 Qt 6.2.2的简短教程
- 刘宇凡:群生?群死?群P?
- 一些常用的dos命令
- 2010年06月12日
- win32 注册表操作
- 检查mysql的replication_MySQL Replication需要注意的问题
- “大鳄”伪装小职员,涉案金额达 5 亿!全球最大游戏外挂案告破
- 电能质量分析仪上位机软件安装和使用
- 香港理工大学ASSIST2011会议(2011-09-30)
- 剑指MBA?Acer发布全高清触控Win8平板Aspire S7
- 每天二十分钟学习python_每天 3 分钟,小闫带你学 Python(二十三)
- DNS的集群与更新(远程更新,加密更新)
- 移动端网页的基础制作
- OA系统中如何实现合同管理?
- python中的数据分析库有哪些_五大常用数据科学Python库
- 产品定位的原则,与同类产品竞争原则、拾遗补缺原则等5个方面
- python基础语法(一)range函数
- python爬虫爬取虎牙数据(简单利用requests库以及Beautifulsoup)
- 【子网划分】求子网网络前缀、子网地址、每个子网可以分配给主机使用的最小地址和最大地址