教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 golang判断结构体为空

golang判断结构体为空

发布时间:2022-03-19   编辑:jiaochengji.com
教程集为您提供golang判断结构体为空等资源,欢迎您收藏本站,我们将为您提供最新的golang判断结构体为空资源
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"/></svg>

golang结构体怎么判断是否为空

golang结构体怎么判断为空?就是判断是否已经初始化,方法如下:

可以使用if objectA== (structname{}){ // your code },进行判断。

示例代码如下:

<pre><code>package main import ( "fmt" "reflect" ) type A struct{ name string age int } func (a A) IsEmpty() bool { return reflect.DeepEqual(a, A{}) } func main() { var a A if a == (A{}) { // 括号不能去 fmt.Println("a == A{} empty") } if a.IsEmpty() { fmt.Println("reflect deep is empty") } } </code></pre> 到此这篇关于“golang判断结构体为空”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
golang判断结构体为空
golang中的nil
golang判断结构体为空_如何在Golang中检查结构是否为空?
GO--接口开发,空结构体如何返回一个空数组
2020-10-18Go语言接口
golang key map 所有_golang系列——高级语法之map
Golang 结构体判空
go语言接口断言的使用
Golang结构体中Tag的使用
golang类型断言(Type Assertion)的应用

[关闭]
~ ~