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)

相关推荐
铁皮饭盒12 分钟前
TypeBox 比 Zod.js 校验 快10倍, 还兼容AI 工具调用, 他做对了什么?
前端·javascript·后端
倔强的石头_8 小时前
WorkBuddy 上手实战:打造一个可用的本地 AI 工作台
后端
苍何14 小时前
Coding 真有质的飞跃?实测下豆包seed 2.1 pro
后端
苍何14 小时前
试了下腾讯 Marvis,回不去了...
后端
caibixyy14 小时前
springboot+langchain4j 实战 Day14——工具嵌入多 Agent(Tool-Equipped Multi-Agent)
后端
caibixyy14 小时前
springboot+langchain4j 实战 Day13 多 Agent 协作(Router + 子 Agent 分流)
后端
飘尘14 小时前
前端转全栈(Java 后端)必须要知道的:开发中的锁机制与分布式并发控制
前端·后端·全栈
苍何14 小时前
清华团队做了个具身智能大脑,有点东西!
后端
fliter14 小时前
强类型的诅咒,还是 Rust 类型系统的生存指南
后端