golang 结构体比较

1.如果结构体成员包含 map, slice, 不可比较

2.int string 普通类型,如果变量顺序不一样,则不可比较

go 复制代码
package main

import "fmt"

func main() {
	s1 := struct {
		//a map[int]int
		// a []int
		a string
		b int
	}{}
	s2 := struct {
		//a map[int]int
		// a []int
		b int
		a string
	}{}

	fmt.Println(s1 == s2)
}

invalid operation: cannot compare s1 == s2 (struct containing mapintint cannot be compared

invalid operation: cannot compare s1 == s2 (struct containing \[\]int cannot be compared)

相关推荐
Wx-bishekaifayuan23 分钟前
springboot甘肃特产服务平台50301-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游
Thneonl25 分钟前
服务不通先别抓包:DNS 解析器的坑比内核网络栈多
后端·程序员
Thneonl25 分钟前
一启动就 Exited(137):内存限制背后藏了四个参数
后端·架构
斯维赤32 分钟前
从 @Tool 到 Agent 流水线:LangChain4j 进阶教学,一个库打全套
java·后端
对象存储与RustFS34 分钟前
RustFS 生产部署实战:Docker / 二进制 / K8s Operator 三条路径怎么选
后端
知守观41 分钟前
Spring Boot 2.1.0 停维护5年,10个依赖4个有CVE——2022年老项目的安全体检报告
spring boot·后端
zhanghaha131443 分钟前
Python进阶教程:35_PyQt (保姆级零基础教程)
开发语言·python·pyqt
SimonKing44 分钟前
SSE项目`nexus-sse`持续优化,不一样的视觉效果
java·后端·程序员
斑鸠喳喳44 分钟前
读写锁模式 Read-Write Lock
java·后端
Thneonl1 小时前
etcd 磁盘写满的那 6 分钟:控制面是怎么一步步瘫的
后端·架构