Missing type in composite literal
首先来看一个示例,它在idea中会直接提示错误。
package mainimport ("fmt"
)type Person struct {Name stringAge intFavourite []string
}func main() {person := Person{"benben_2015",18,{"huoguo", "chuanchuan"},}fmt.Println(person)
}
上面代码在编辑器中会提示这样的错误:Reports composite literals with incompatible types and values
。原因在于定义的Person结构体的Favourite字段的类型是字符串切片,但是在main函数中使用时,直接传入了一个结构体对象。两者的类型不相同,所以提示不兼容的类型。
对于一些复合数据类型,在使用时应该声明其类型信息,不然Go无法自动判别。因此上面的错误示例只需要改变person初始化时的类型声明即可。
func main() {person := Person{"benben_2015",18,[]string{"huoguo", "chuanchuan"},}
}
Missing type in composite literal相关推荐
- redisson get()数据报错,missing type id property ‘@class’
redisson get()数据报错: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when ...
- (转)java.lang.RuntimeException: Missing type parameter
java.lang.RuntimeException: Missing type parameter (2015-04-07 14:35:51) 分类: 技术 程序中用到了gson的new typ ...
- UE4 报错 missing type specifier - int assumed
没有提示的错误,但是编译时就出现:missing type specifier - int assumed 我出现的原因是在使用MergeActor时, #include "Editor/M ...
- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 解决方法
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 解决方法 参考文章: ...
- ITextRenderer refers to the missing type DocumentException
1.The method createPDF(OutputStream) from the type ITextRenderer refers to the missing type Document ...
- golang报错 missing key in map literal
map[string]interface{}用法见:golang学习笔记 ---解析(map[string]interface{})数据格式 - 清明-心若淡定 - 博客园 解决方法见: Golang ...
- realease包出现–missing type parameter
项目中用到了gson,在解析时用到了 Type listType = new TypeToken<>(){}.getType(); 当使用debug包时进行网络请求没有问题,但是当把项目打 ...
- golang 操作 mongodb 时vscode提示 primitive.E composite literal uses unkeyed fields 的解决办法
cannot use "category_title" (untyped string constant) as primitive.E value in array or sli ...
- The method createCall() from the type Service refers to the missing type Call
2019独角兽企业重金招聘Python工程师标准>>> 解决方案 (1)引用J2EE包(其实只需要 jboss-jaxrpc.jar ) (2)或者从axis-bin-x.zip 中 ...
最新文章
- angular directive 深入理解
- 科幻片天际SKYLINE,喜欢科幻的朋友不要错过。
- 技巧:Silverlight应用程序中如何获取ASP.NET页面参数
- 学python还是php2019_有2019年开始学PHP的人吗,可不可以分享一下你是如何考虑的?...
- PHP和MySQL处理树状、分级、无限分类、分层数据的方法
- vue 项目中使用粘性布局不起作用_做vue项目中遇到的坑总结与学习
- ServletContextListener小小总结
- 绘图QPainter-字体
- lammps教程:NEMD方法计算热导率公式详解
- mysql手册02_事务
- python数据分析基础阮敬源码_python数据分析基础 阮敬pdf|保靖制作项目投资实施细则...
- 全自动抠图换背景软件下载_抠图换背景app下载-抠图换背景下载v1.1.6 安卓版-西西软件下载...
- baiduexporter+Aria在Chrome最新版上的尝试(2020.07)
- linux基础-mkdir touch cp
- PL330 DMAC笔记(1) - 简介
- ubuntu redis desktop manager 编译问题解决
- ISA8051内部结构讲解
- 代码 羊角螺旋_机电设计中的数学之美——羊角螺旋让你平稳过弯
- win7重装的坑:启动分区不存在 使用分区工具修正
- SNAT和DNAT简介