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)

相关推荐
步行cgn10 小时前
@Configuration 详解:Spring 配置类的核心注解
java·后端·spring
事圆则缓11 小时前
Kotlin 协程完全指南
开发语言·kotlin
我爱写代码i11 小时前
BeLink - 支持生成多种URL 缩短网址PHP源码
开发语言·php·短网址php源码
Java后端的Ai之路11 小时前
20、Python - 备忘录模式
开发语言·人工智能·python·外观模式·备忘录模式
桦说编程12 小时前
【AtomicAgent系列1】变异测试——过去做不起,现在 agent 做得起
后端·ai编程·vibecoding
统计学小王子12 小时前
数学建模国赛倒计时4天——《统计模型精讲(混合效应模型R语言实现)》
开发语言·数学建模·r语言
知无不研12 小时前
c语言中循环的介绍与简单应用
c语言·开发语言·算法·循环·for·while
郝学胜-神的一滴12 小时前
Qt 高级编程 045:坐标体系深度实战
开发语言·c++·windows·python·qt·程序人生
dsyyyyy110113 小时前
JS复习,难点,易错点总结
开发语言·javascript·ecmascript
考虑考虑13 小时前
nginx打印请求日志
运维·后端·nginx