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)

相关推荐
amazingCompass1 分钟前
Java 开发必备技能:深入理解与实战 IntelliJ IDEA 中的 VM Options
后端
每天的每一天9 分钟前
分布式文件系统05-生产级中间件的Java网络通信技术深度优化
java·开发语言·中间件
欧的曼24 分钟前
cygwin+php教程(swoole扩展+redis扩展)
开发语言·redis·后端·mysql·nginx·php·swoole
巴拉巴巴巴拉28 分钟前
Spring Boot 整合 Thymeleaf
java·spring boot·后端
智江鹏35 分钟前
Android 之 Kotlin中的符号
android·开发语言·kotlin
用户15129054522044 分钟前
Docker部署 Alist
后端
白应穷奇1 小时前
Diesel的高性能特性: 深入理解Rust ORM的性能优化
后端·rust
用户1512905452201 小时前
HDOJ-ACM1017(JAVA)
后端
Ray661 小时前
OOP 四大特征
后端
艾莉丝努力练剑1 小时前
【C/C++】形参、实参相关内容整理
c语言·开发语言·c++·学习