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 map[int]int cannot be compared

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

相关推荐
独自破碎E9 小时前
【曼哈顿距离】BISHI25 最大 FST 距离
java·开发语言
苏涵.9 小时前
Java三大集合:List、Set、Map
java·开发语言
Amumu121389 小时前
Vue3 Composition API(一)
开发语言·javascript·ecmascript
存在的五月雨9 小时前
Spring Security认证流程
java·开发语言·mysql
树码小子9 小时前
综合练习:验证码案例(1)总体设计
java·开发语言·spring
草莓熊Lotso9 小时前
Qt 主窗口核心组件实战:菜单栏、工具栏、状态栏、浮动窗口全攻略
运维·开发语言·人工智能·python·qt·ui
Ronin3059 小时前
持久化数据管理中心模块
开发语言·c++·rabbitmq·gtest
froginwe119 小时前
AJAX 实例详解
开发语言
魔力军9 小时前
Rust学习Day2: 变量与可变性、数据类型和函数和控制流
开发语言·学习·rust
sycmancia9 小时前
C++——强制类型转化、const的理解
开发语言·c++