首先来看一个示例,它在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相关推荐

  1. redisson get()数据报错,missing type id property ‘@class’

    redisson get()数据报错: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when ...

  2. (转)java.lang.RuntimeException: Missing type parameter

    java.lang.RuntimeException: Missing type parameter (2015-04-07 14:35:51)   分类: 技术 程序中用到了gson的new typ ...

  3. UE4 报错 missing type specifier - int assumed

    没有提示的错误,但是编译时就出现:missing type specifier - int assumed 我出现的原因是在使用MergeActor时, #include "Editor/M ...

  4. 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 解决方法 参考文章: ...

  5. ITextRenderer refers to the missing type DocumentException

    1.The method createPDF(OutputStream) from the type ITextRenderer refers to the missing type Document ...

  6. golang报错 missing key in map literal

    map[string]interface{}用法见:golang学习笔记 ---解析(map[string]interface{})数据格式 - 清明-心若淡定 - 博客园 解决方法见: Golang ...

  7. realease包出现–missing type parameter

    项目中用到了gson,在解析时用到了 Type listType = new TypeToken<>(){}.getType(); 当使用debug包时进行网络请求没有问题,但是当把项目打 ...

  8. 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 ...

  9. 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 中 ...

最新文章

  1. angular directive 深入理解
  2. 科幻片天际SKYLINE,喜欢科幻的朋友不要错过。
  3. 技巧:Silverlight应用程序中如何获取ASP.NET页面参数
  4. 学python还是php2019_有2019年开始学PHP的人吗,可不可以分享一下你是如何考虑的?...
  5. PHP和MySQL处理树状、分级、无限分类、分层数据的方法
  6. vue 项目中使用粘性布局不起作用_做vue项目中遇到的坑总结与学习
  7. ServletContextListener小小总结
  8. 绘图QPainter-字体
  9. lammps教程:NEMD方法计算热导率公式详解
  10. mysql手册02_事务
  11. python数据分析基础阮敬源码_python数据分析基础 阮敬pdf|保靖制作项目投资实施细则...
  12. 全自动抠图换背景软件下载_抠图换背景app下载-抠图换背景下载v1.1.6 安卓版-西西软件下载...
  13. baiduexporter+Aria在Chrome最新版上的尝试(2020.07)
  14. linux基础-mkdir touch cp
  15. PL330 DMAC笔记(1) - 简介
  16. ubuntu redis desktop manager 编译问题解决
  17. ISA8051内部结构讲解
  18. 代码 羊角螺旋_机电设计中的数学之美——羊角螺旋让你平稳过弯
  19. win7重装的坑:启动分区不存在 使用分区工具修正
  20. SNAT和DNAT简介

热门文章

  1. 这六种简历,HR拒绝浏览!
  2. 公众号1200篇文章分类和索引
  3. C# Winform 无弹窗打印实例
  4. 424 B. Megacity
  5. 回溯算法(以解决n皇后问题为例)
  6. SpringSecurity自定义投票器
  7. AE电子相册模板|笔刷特效照片回忆展示AE幻灯片模板
  8. 无损音乐格式转换的方法
  9. 拒绝不合理,不可能完成的任务
  10. springboot+mysql物流车辆管理系统-计算机设计源码84722